--DO NOT MODIFY THIS FILE. IT IS ALWAYS OVERWRITTEN ON GENERATION.
--Data Schema For Version 1.0.0.0

--CREATE TABLE [Administrator]
if not exists(select * from sysobjects where name = 'Administrator' and xtype = 'U')
CREATE TABLE [dbo].[Administrator] (
	[Active] [Bit] NOT NULL CONSTRAINT [DF__ADMINISTRATOR_ACTIVE] DEFAULT (1),
	[AdministratorId] [Int] IDENTITY (1, 1) NOT NULL ,
	[Email] [VarChar] (50) NOT NULL ,
	[FirstName] [VarChar] (50) NOT NULL ,
	[LastIpAddress] [VarChar] (15) NOT NULL CONSTRAINT [DF__ADMINISTRATOR_LASTIPADDRESS] DEFAULT ('0.0.0.0'),
	[LastName] [VarChar] (50) NOT NULL ,
	[Password] [VarChar] (100) NOT NULL ,
	[UserName] [VarChar] (50) NOT NULL ,
	[ModifiedBy] [Varchar] (50) NULL,
	[ModifiedDate] [DateTime] CONSTRAINT [DF__ADMINISTRATOR_MODIFIEDDATE] DEFAULT getdate() NULL,
	[CreatedBy] [Varchar] (50) NULL,
	[CreatedDate] [DateTime] CONSTRAINT [DF__ADMINISTRATOR_CREATEDDATE] DEFAULT getdate() NULL,
	[TimeStamp] [timestamp] NOT NULL
)

GO

--CREATE TABLE [BodyType]
if not exists(select * from sysobjects where name = 'BodyType' and xtype = 'U')
CREATE TABLE [dbo].[BodyType] (
	[BodyTypeId] [Int] IDENTITY (1, 1) NOT NULL ,
	[Name] [VarChar] (50) NOT NULL ,
	[ModifiedBy] [Varchar] (50) NULL,
	[ModifiedDate] [DateTime] CONSTRAINT [DF__BODYTYPE_MODIFIEDDATE] DEFAULT getdate() NULL,
	[CreatedBy] [Varchar] (50) NULL,
	[CreatedDate] [DateTime] CONSTRAINT [DF__BODYTYPE_CREATEDDATE] DEFAULT getdate() NULL,
	[TimeStamp] [timestamp] NOT NULL
)

GO

--CREATE TABLE [BulletPoint]
if not exists(select * from sysobjects where name = 'BulletPoint' and xtype = 'U')
CREATE TABLE [dbo].[BulletPoint] (
	[BulletPointId] [Int] IDENTITY (1, 1) NOT NULL ,
	[ListingId] [Int] NOT NULL ,
	[Text] [VarChar] (500) NOT NULL ,
	[ModifiedBy] [Varchar] (50) NULL,
	[ModifiedDate] [DateTime] CONSTRAINT [DF__BULLETPOINT_MODIFIEDDATE] DEFAULT getdate() NULL,
	[CreatedBy] [Varchar] (50) NULL,
	[CreatedDate] [DateTime] CONSTRAINT [DF__BULLETPOINT_CREATEDDATE] DEFAULT getdate() NULL,
	[TimeStamp] [timestamp] NOT NULL
)

GO

--CREATE TABLE [City]
if not exists(select * from sysobjects where name = 'City' and xtype = 'U')
CREATE TABLE [dbo].[City] (
	[CityId] [Int] IDENTITY (1, 1) NOT NULL ,
	[Name] [VarChar] (100) NOT NULL ,
	[StateId] [Int] NOT NULL ,
	[ModifiedBy] [Varchar] (50) NULL,
	[ModifiedDate] [DateTime] CONSTRAINT [DF__CITY_MODIFIEDDATE] DEFAULT getdate() NULL,
	[CreatedBy] [Varchar] (50) NULL,
	[CreatedDate] [DateTime] CONSTRAINT [DF__CITY_CREATEDDATE] DEFAULT getdate() NULL,
	[TimeStamp] [timestamp] NOT NULL
)

GO

--CREATE TABLE [CityZip]
if not exists(select * from sysobjects where name = 'CityZip' and xtype = 'U')
CREATE TABLE [dbo].[CityZip] (
	[CityId] [Int] NOT NULL ,
	[ZipId] [Int] NOT NULL )

GO

--CREATE TABLE [Color]
if not exists(select * from sysobjects where name = 'Color' and xtype = 'U')
CREATE TABLE [dbo].[Color] (
	[ColorId] [Int] IDENTITY (1, 1) NOT NULL ,
	[Name] [VarChar] (50) NOT NULL ,
	[ModifiedBy] [Varchar] (50) NULL,
	[ModifiedDate] [DateTime] CONSTRAINT [DF__COLOR_MODIFIEDDATE] DEFAULT getdate() NULL,
	[CreatedBy] [Varchar] (50) NULL,
	[CreatedDate] [DateTime] CONSTRAINT [DF__COLOR_CREATEDDATE] DEFAULT getdate() NULL,
	[TimeStamp] [timestamp] NOT NULL
)

GO

--CREATE TABLE [Condition]
if not exists(select * from sysobjects where name = 'Condition' and xtype = 'U')
CREATE TABLE [dbo].[Condition] (
	[ConditionId] [Int] IDENTITY (1, 1) NOT NULL ,
	[Name] [VarChar] (50) NULL ,
	[ModifiedBy] [Varchar] (50) NULL,
	[ModifiedDate] [DateTime] CONSTRAINT [DF__CONDITION_MODIFIEDDATE] DEFAULT getdate() NULL,
	[CreatedBy] [Varchar] (50) NULL,
	[CreatedDate] [DateTime] CONSTRAINT [DF__CONDITION_CREATEDDATE] DEFAULT getdate() NULL,
	[TimeStamp] [timestamp] NOT NULL
)

GO

--CREATE TABLE [ConfigSetting]
if not exists(select * from sysobjects where name = 'ConfigSetting' and xtype = 'U')
CREATE TABLE [dbo].[ConfigSetting] (
	[ID] [Int] IDENTITY (1, 1) NOT NULL ,
	[Name] [VarChar] (50) NOT NULL ,
	[Value] [VarChar] (100) NOT NULL ,
	[ModifiedBy] [Varchar] (50) NULL,
	[ModifiedDate] [DateTime] CONSTRAINT [DF__CONFIGSETTING_MODIFIEDDATE] DEFAULT getdate() NULL,
	[CreatedBy] [Varchar] (50) NULL,
	[CreatedDate] [DateTime] CONSTRAINT [DF__CONFIGSETTING_CREATEDDATE] DEFAULT getdate() NULL,
	[TimeStamp] [timestamp] NOT NULL
)

GO

--CREATE TABLE [Dealer]
if not exists(select * from sysobjects where name = 'Dealer' and xtype = 'U')
CREATE TABLE [dbo].[Dealer] (
	[CompanyName] [VarChar] (50) NOT NULL ,
	[Directions] [VarChar] (500) NULL ,
	[MetroId] [Int] NULL ,
	[UserId] [Int] NOT NULL ,
	[ModifiedBy] [Varchar] (50) NULL,
	[ModifiedDate] [DateTime] CONSTRAINT [DF__DEALER_MODIFIEDDATE] DEFAULT getdate() NULL,
	[CreatedBy] [Varchar] (50) NULL,
	[CreatedDate] [DateTime] CONSTRAINT [DF__DEALER_CREATEDDATE] DEFAULT getdate() NULL,
	[TimeStamp] [timestamp] NOT NULL
)

GO

--CREATE TABLE [Feature]
if not exists(select * from sysobjects where name = 'Feature' and xtype = 'U')
CREATE TABLE [dbo].[Feature] (
	[FeatureId] [Int] IDENTITY (1, 1) NOT NULL ,
	[Name] [VarChar] (50) NOT NULL ,
	[ModifiedBy] [Varchar] (50) NULL,
	[ModifiedDate] [DateTime] CONSTRAINT [DF__FEATURE_MODIFIEDDATE] DEFAULT getdate() NULL,
	[CreatedBy] [Varchar] (50) NULL,
	[CreatedDate] [DateTime] CONSTRAINT [DF__FEATURE_CREATEDDATE] DEFAULT getdate() NULL,
	[TimeStamp] [timestamp] NOT NULL
)

GO

--CREATE TABLE [FuelType]
if not exists(select * from sysobjects where name = 'FuelType' and xtype = 'U')
CREATE TABLE [dbo].[FuelType] (
	[FuelTypeId] [Int] IDENTITY (1, 1) NOT NULL ,
	[Name] [VarChar] (50) NOT NULL ,
	[ModifiedBy] [Varchar] (50) NULL,
	[ModifiedDate] [DateTime] CONSTRAINT [DF__FUELTYPE_MODIFIEDDATE] DEFAULT getdate() NULL,
	[CreatedBy] [Varchar] (50) NULL,
	[CreatedDate] [DateTime] CONSTRAINT [DF__FUELTYPE_CREATEDDATE] DEFAULT getdate() NULL,
	[TimeStamp] [timestamp] NOT NULL
)

GO

--CREATE TABLE [Listing]
if not exists(select * from sysobjects where name = 'Listing' and xtype = 'U')
CREATE TABLE [dbo].[Listing] (
	[Active] [Bit] NOT NULL CONSTRAINT [DF__LISTING_ACTIVE] DEFAULT (1),
	[BodyTypeId] [Int] NULL ,
	[ColorExtId] [Int] NOT NULL ,
	[ColorIntId] [Int] NOT NULL ,
	[ConditionId] [Int] NULL ,
	[Cylinders] [Int] NULL ,
	[Description] [VarChar] (1000) NULL ,
	[Disclaimer] [VarChar] (5000) NULL ,
	[Doors] [Int] NULL ,
	[Engine] [VarChar] (100) NULL ,
	[ExpirationDate] [DateTime] NOT NULL CONSTRAINT [DF__LISTING_EXPIRATIONDATE] DEFAULT (getdate()),
	[FuelTypeId] [Int] NULL ,
	[Invoice] [Int] NULL ,
	[IsFeatured] [Bit] NULL ,
	[ListDate] [DateTime] NULL ,
	[ListingId] [Int] IDENTITY (1, 1) NOT NULL ,
	[MakeModelId] [Int] NOT NULL ,
	[MetroId] [Int] NULL ,
	[Mileage] [Int] NOT NULL ,
	[Price] [Int] NOT NULL ,
	[StockNumber] [VarChar] (50) NULL ,
	[Title] [VarChar] (100) NULL ,
	[TransmissionId] [Int] NULL ,
	[TrimLevel] [VarChar] (10) NULL ,
	[UserId] [Int] NOT NULL ,
	[Vin] [VarChar] (50) NULL ,
	[Year] [Int] NOT NULL ,
	[ModifiedBy] [Varchar] (50) NULL,
	[ModifiedDate] [DateTime] CONSTRAINT [DF__LISTING_MODIFIEDDATE] DEFAULT getdate() NULL,
	[CreatedBy] [Varchar] (50) NULL,
	[CreatedDate] [DateTime] CONSTRAINT [DF__LISTING_CREATEDDATE] DEFAULT getdate() NULL,
	[TimeStamp] [timestamp] NOT NULL
)

GO

--CREATE TABLE [ListingFeature]
if not exists(select * from sysobjects where name = 'ListingFeature' and xtype = 'U')
CREATE TABLE [dbo].[ListingFeature] (
	[FeatureId] [Int] NOT NULL ,
	[ListingId] [Int] NOT NULL )

GO

--CREATE TABLE [ListingImage]
if not exists(select * from sysobjects where name = 'ListingImage' and xtype = 'U')
CREATE TABLE [dbo].[ListingImage] (
	[FileName] [VarChar] (100) NOT NULL ,
	[ListingId] [Int] NOT NULL ,
	[ListingImageId] [Int] IDENTITY (1, 1) NOT NULL ,
	[SortOrder] [Int] NULL ,
	[ModifiedBy] [Varchar] (50) NULL,
	[ModifiedDate] [DateTime] CONSTRAINT [DF__LISTINGIMAGE_MODIFIEDDATE] DEFAULT getdate() NULL,
	[CreatedBy] [Varchar] (50) NULL,
	[CreatedDate] [DateTime] CONSTRAINT [DF__LISTINGIMAGE_CREATEDDATE] DEFAULT getdate() NULL,
	[TimeStamp] [timestamp] NOT NULL
)

GO

--CREATE TABLE [ListingPremium]
if not exists(select * from sysobjects where name = 'ListingPremium' and xtype = 'U')
CREATE TABLE [dbo].[ListingPremium] (
	[Active] [Bit] NOT NULL CONSTRAINT [DF__LISTINGPREMIUM_ACTIVE] DEFAULT (1),
	[CityName] [VarChar] (50) NOT NULL ,
	[ExpirationDate] [DateTime] NOT NULL ,
	[ListingId] [Int] NOT NULL ,
	[ListingPremiumId] [Int] IDENTITY (1, 1) NOT NULL ,
	[StartDate] [DateTime] NOT NULL ,
	[StateId] [Int] NOT NULL ,
	[ModifiedBy] [Varchar] (50) NULL,
	[ModifiedDate] [DateTime] CONSTRAINT [DF__LISTINGPREMIUM_MODIFIEDDATE] DEFAULT getdate() NULL,
	[CreatedBy] [Varchar] (50) NULL,
	[CreatedDate] [DateTime] CONSTRAINT [DF__LISTINGPREMIUM_CREATEDDATE] DEFAULT getdate() NULL,
	[TimeStamp] [timestamp] NOT NULL
)

GO

--CREATE TABLE [ListingSaved]
if not exists(select * from sysobjects where name = 'ListingSaved' and xtype = 'U')
CREATE TABLE [dbo].[ListingSaved] (
	[ListingId] [Int] NOT NULL ,
	[UserId] [Int] NOT NULL ,
	[ModifiedBy] [Varchar] (50) NULL,
	[ModifiedDate] [DateTime] CONSTRAINT [DF__LISTINGSAVED_MODIFIEDDATE] DEFAULT getdate() NULL,
	[CreatedBy] [Varchar] (50) NULL,
	[CreatedDate] [DateTime] CONSTRAINT [DF__LISTINGSAVED_CREATEDDATE] DEFAULT getdate() NULL,
	[TimeStamp] [timestamp] NOT NULL
)

GO

--CREATE TABLE [ListingView]
if not exists(select * from sysobjects where name = 'ListingView' and xtype = 'U')
CREATE TABLE [dbo].[ListingView] (
	[ListingId] [Int] NOT NULL ,
	[ListingViewId] [Int] IDENTITY (1, 1) NOT NULL ,
	[CreatedBy] [Varchar] (50) NULL,
	[CreatedDate] [DateTime] CONSTRAINT [DF__LISTINGVIEW_CREATEDDATE] DEFAULT getdate() NULL)

GO

--CREATE TABLE [Make]
if not exists(select * from sysobjects where name = 'Make' and xtype = 'U')
CREATE TABLE [dbo].[Make] (
	[MakeId] [Int] IDENTITY (1, 1) NOT NULL ,
	[Name] [VarChar] (50) NOT NULL ,
	[ModifiedBy] [Varchar] (50) NULL,
	[ModifiedDate] [DateTime] CONSTRAINT [DF__MAKE_MODIFIEDDATE] DEFAULT getdate() NULL,
	[CreatedBy] [Varchar] (50) NULL,
	[CreatedDate] [DateTime] CONSTRAINT [DF__MAKE_CREATEDDATE] DEFAULT getdate() NULL,
	[TimeStamp] [timestamp] NOT NULL
)

GO

--CREATE TABLE [MakeModel]
if not exists(select * from sysobjects where name = 'MakeModel' and xtype = 'U')
CREATE TABLE [dbo].[MakeModel] (
	[MakeId] [Int] NOT NULL ,
	[MakeModelId] [Int] IDENTITY (1, 1) NOT NULL ,
	[ModelId] [Int] NOT NULL ,
	[ModifiedBy] [Varchar] (50) NULL,
	[ModifiedDate] [DateTime] CONSTRAINT [DF__MAKEMODEL_MODIFIEDDATE] DEFAULT getdate() NULL,
	[CreatedBy] [Varchar] (50) NULL,
	[CreatedDate] [DateTime] CONSTRAINT [DF__MAKEMODEL_CREATEDDATE] DEFAULT getdate() NULL,
	[TimeStamp] [timestamp] NOT NULL
)

GO

--CREATE TABLE [Metro]
if not exists(select * from sysobjects where name = 'Metro' and xtype = 'U')
CREATE TABLE [dbo].[Metro] (
	[IsPopular] [VarChar] (1) NOT NULL CONSTRAINT [DF__METRO_ISPOPULAR] DEFAULT ('0'),
	[MetroId] [Int] IDENTITY (1, 1) NOT NULL ,
	[Name] [VarChar] (50) NOT NULL ,
	[ModifiedBy] [Varchar] (50) NULL,
	[ModifiedDate] [DateTime] CONSTRAINT [DF__METRO_MODIFIEDDATE] DEFAULT getdate() NULL,
	[CreatedBy] [Varchar] (50) NULL,
	[CreatedDate] [DateTime] CONSTRAINT [DF__METRO_CREATEDDATE] DEFAULT getdate() NULL,
	[TimeStamp] [timestamp] NOT NULL
)

GO

--CREATE TABLE [MetroState]
if not exists(select * from sysobjects where name = 'MetroState' and xtype = 'U')
CREATE TABLE [dbo].[MetroState] (
	[MetroId] [Int] NOT NULL ,
	[StateId] [Int] NOT NULL )

GO

--CREATE TABLE [MetroZip]
if not exists(select * from sysobjects where name = 'MetroZip' and xtype = 'U')
CREATE TABLE [dbo].[MetroZip] (
	[MetroId] [Int] NOT NULL ,
	[ZipId] [Int] NOT NULL )

GO

--CREATE TABLE [Model]
if not exists(select * from sysobjects where name = 'Model' and xtype = 'U')
CREATE TABLE [dbo].[Model] (
	[ModelId] [Int] IDENTITY (1, 1) NOT NULL ,
	[MpgCity] [Int] NULL ,
	[MpgHighway] [Int] NULL ,
	[Name] [VarChar] (50) NOT NULL ,
	[ModifiedBy] [Varchar] (50) NULL,
	[ModifiedDate] [DateTime] CONSTRAINT [DF__MODEL_MODIFIEDDATE] DEFAULT getdate() NULL,
	[CreatedBy] [Varchar] (50) NULL,
	[CreatedDate] [DateTime] CONSTRAINT [DF__MODEL_CREATEDDATE] DEFAULT getdate() NULL,
	[TimeStamp] [timestamp] NOT NULL
)

GO

--CREATE TABLE [SearchSaved]
if not exists(select * from sysobjects where name = 'SearchSaved' and xtype = 'U')
CREATE TABLE [dbo].[SearchSaved] (
	[Location] [VarChar] (100) NULL ,
	[Name] [VarChar] (50) NOT NULL ,
	[Radius] [Int] NULL ,
	[SearchSavedId] [Int] IDENTITY (1, 1) NOT NULL ,
	[Text] [VarChar] (100) NULL ,
	[UserId] [Int] NOT NULL ,
	[ModifiedBy] [Varchar] (50) NULL,
	[ModifiedDate] [DateTime] CONSTRAINT [DF__SEARCHSAVED_MODIFIEDDATE] DEFAULT getdate() NULL,
	[CreatedBy] [Varchar] (50) NULL,
	[CreatedDate] [DateTime] CONSTRAINT [DF__SEARCHSAVED_CREATEDDATE] DEFAULT getdate() NULL,
	[TimeStamp] [timestamp] NOT NULL
)

GO

--CREATE TABLE [SearchSavedCriteria]
if not exists(select * from sysobjects where name = 'SearchSavedCriteria' and xtype = 'U')
CREATE TABLE [dbo].[SearchSavedCriteria] (
	[Didx] [Int] NOT NULL ,
	[Dvidx] [Int] NOT NULL ,
	[SearchSavedCriteriaId] [Int] IDENTITY (1, 1) NOT NULL ,
	[SearchSavedId] [Int] NOT NULL ,
	[ModifiedBy] [Varchar] (50) NULL,
	[ModifiedDate] [DateTime] CONSTRAINT [DF__SEARCHSAVEDCRITERIA_MODIFIEDDATE] DEFAULT getdate() NULL,
	[CreatedBy] [Varchar] (50) NULL,
	[CreatedDate] [DateTime] CONSTRAINT [DF__SEARCHSAVEDCRITERIA_CREATEDDATE] DEFAULT getdate() NULL,
	[TimeStamp] [timestamp] NOT NULL
)

GO

--CREATE TABLE [State]
if not exists(select * from sysobjects where name = 'State' and xtype = 'U')
CREATE TABLE [dbo].[State] (
	[Abbr] [VarChar] (2) NOT NULL ,
	[Description] [VarChar] (4000) NOT NULL ,
	[Name] [VarChar] (50) NOT NULL ,
	[StateId] [Int] IDENTITY (1, 1) NOT NULL ,
	[ModifiedBy] [Varchar] (50) NULL,
	[ModifiedDate] [DateTime] CONSTRAINT [DF__STATE_MODIFIEDDATE] DEFAULT getdate() NULL,
	[CreatedBy] [Varchar] (50) NULL,
	[CreatedDate] [DateTime] CONSTRAINT [DF__STATE_CREATEDDATE] DEFAULT getdate() NULL,
	[TimeStamp] [timestamp] NOT NULL
)

GO

--CREATE TABLE [Transmission]
if not exists(select * from sysobjects where name = 'Transmission' and xtype = 'U')
CREATE TABLE [dbo].[Transmission] (
	[Name] [VarChar] (50) NOT NULL ,
	[TransmissionId] [Int] IDENTITY (1, 1) NOT NULL ,
	[ModifiedBy] [Varchar] (50) NULL,
	[ModifiedDate] [DateTime] CONSTRAINT [DF__TRANSMISSION_MODIFIEDDATE] DEFAULT getdate() NULL,
	[CreatedBy] [Varchar] (50) NULL,
	[CreatedDate] [DateTime] CONSTRAINT [DF__TRANSMISSION_CREATEDDATE] DEFAULT getdate() NULL,
	[TimeStamp] [timestamp] NOT NULL
)

GO

--CREATE TABLE [UserAccount]
if not exists(select * from sysobjects where name = 'UserAccount' and xtype = 'U')
CREATE TABLE [dbo].[UserAccount] (
	[AcceptedAdvertTerms] [Bit] NOT NULL CONSTRAINT [DF__USERACCOUNT_ACCEPTEDADVERTTERMS] DEFAULT (0),
	[Active] [Bit] NOT NULL CONSTRAINT [DF__USERACCOUNT_ACTIVE] DEFAULT (1),
	[Address1] [VarChar] (150) NULL ,
	[Address2] [VarChar] (150) NULL ,
	[AlertFrequency] [Int] NOT NULL CONSTRAINT [DF__USERACCOUNT_ALERTFREQUENCY] DEFAULT (7),
	[AlertSent] [DateTime] NULL CONSTRAINT [DF__USERACCOUNT_ALERTSENT] DEFAULT (getdate()),
	[City] [VarChar] (100) NULL ,
	[Description] [NText] NULL ,
	[Email] [VarChar] (175) NOT NULL ,
	[FirstName] [VarChar] (100) NOT NULL ,
	[HomePhone] [VarChar] (20) NULL ,
	[LastName] [VarChar] (100) NOT NULL ,
	[Latitude] [Float] NULL ,
	[Longitude] [Float] NULL ,
	[MobilePhone] [VarChar] (20) NULL ,
	[OfficeFax] [VarChar] (20) NULL ,
	[OfficePhone] [VarChar] (20) NULL ,
	[OfficePhoneExt] [VarChar] (10) NULL ,
	[Password] [VarChar] (100) NOT NULL ,
	[StateId] [Int] NOT NULL ,
	[UserId] [Int] IDENTITY (1, 1) NOT NULL ,
	[UserTypeId] [Int] NOT NULL ,
	[ZipId] [Int] NULL ,
	[ModifiedBy] [Varchar] (50) NULL,
	[ModifiedDate] [DateTime] CONSTRAINT [DF__USERACCOUNT_MODIFIEDDATE] DEFAULT getdate() NULL,
	[CreatedBy] [Varchar] (50) NULL,
	[CreatedDate] [DateTime] CONSTRAINT [DF__USERACCOUNT_CREATEDDATE] DEFAULT getdate() NULL,
	[TimeStamp] [timestamp] NOT NULL
)

GO

--CREATE TABLE [UserLoginHistory]
if not exists(select * from sysobjects where name = 'UserLoginHistory' and xtype = 'U')
CREATE TABLE [dbo].[UserLoginHistory] (
	[BrowserAgent] [VarChar] (255) NULL ,
	[IpAddress] [VarChar] (15) NOT NULL CONSTRAINT [DF__USERLOGINHISTORY_IPADDRESS] DEFAULT ('000.000.000.000'),
	[UserId] [Int] NOT NULL ,
	[UserLoginHistoryId] [Int] IDENTITY (1, 1) NOT NULL ,
	[CreatedBy] [Varchar] (50) NULL,
	[CreatedDate] [DateTime] CONSTRAINT [DF__USERLOGINHISTORY_CREATEDDATE] DEFAULT getdate() NULL)

GO

--CREATE TABLE [UserType]
if not exists(select * from sysobjects where name = 'UserType' and xtype = 'U')
CREATE TABLE [dbo].[UserType] (
	[Active] [Bit] NOT NULL CONSTRAINT [DF__USERTYPE_ACTIVE] DEFAULT (1),
	[Name] [VarChar] (50) NOT NULL ,
	[UserTypeId] [Int] IDENTITY (1, 1) NOT NULL ,
	[ModifiedBy] [Varchar] (50) NULL,
	[ModifiedDate] [DateTime] CONSTRAINT [DF__USERTYPE_MODIFIEDDATE] DEFAULT getdate() NULL,
	[CreatedBy] [Varchar] (50) NULL,
	[CreatedDate] [DateTime] CONSTRAINT [DF__USERTYPE_CREATEDDATE] DEFAULT getdate() NULL,
	[TimeStamp] [timestamp] NOT NULL
)

GO

--CREATE TABLE [VistorContact]
if not exists(select * from sysobjects where name = 'VistorContact' and xtype = 'U')
CREATE TABLE [dbo].[VistorContact] (
	[Email] [VarChar] (128) NULL ,
	[IpAddress] [Char] (15) NOT NULL CONSTRAINT [DF__VISTORCONTACT_IPADDRESS] DEFAULT ('000.000.000.000'),
	[IsHandled] [Bit] NOT NULL CONSTRAINT [DF__VISTORCONTACT_ISHANDLED] DEFAULT (0),
	[Message] [Text] NOT NULL ,
	[Name] [VarChar] (100) NULL ,
	[Phone] [VarChar] (15) NULL ,
	[UserId] [Int] NULL ,
	[VisitorContactId] [Int] IDENTITY (1, 1) NOT NULL ,
	[ModifiedBy] [Varchar] (50) NULL,
	[ModifiedDate] [DateTime] CONSTRAINT [DF__VISTORCONTACT_MODIFIEDDATE] DEFAULT getdate() NULL,
	[CreatedBy] [Varchar] (50) NULL,
	[CreatedDate] [DateTime] CONSTRAINT [DF__VISTORCONTACT_CREATEDDATE] DEFAULT getdate() NULL,
	[TimeStamp] [timestamp] NOT NULL
)

GO

--CREATE TABLE [Zip]
if not exists(select * from sysobjects where name = 'Zip' and xtype = 'U')
CREATE TABLE [dbo].[Zip] (
	[Latitude] [Float] NULL ,
	[Longitude] [Float] NULL ,
	[Name] [VarChar] (10) NOT NULL ,
	[StateId] [Int] NULL ,
	[ZipId] [Int] IDENTITY (1, 1) NOT NULL ,
	[ModifiedBy] [Varchar] (50) NULL,
	[ModifiedDate] [DateTime] CONSTRAINT [DF__ZIP_MODIFIEDDATE] DEFAULT getdate() NULL,
	[CreatedBy] [Varchar] (50) NULL,
	[CreatedDate] [DateTime] CONSTRAINT [DF__ZIP_CREATEDDATE] DEFAULT getdate() NULL,
	[TimeStamp] [timestamp] NOT NULL
)

GO

--##SECTION BEGIN [FIELD CREATE]
--TABLE [Administrator] ADD FIELDS
if exists(select * from sys.objects where name = 'Administrator' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'Active' and o.name = 'Administrator')
ALTER TABLE [dbo].[Administrator] ADD [Active] [Bit] NOT NULL CONSTRAINT [DF__ADMINISTRATOR_ACTIVE] DEFAULT (1)
if exists(select * from sys.objects where name = 'Administrator' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'AdministratorId' and o.name = 'Administrator')
ALTER TABLE [dbo].[Administrator] ADD [AdministratorId] [Int] IDENTITY (1, 1) NOT NULL 
if exists(select * from sys.objects where name = 'Administrator' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'Email' and o.name = 'Administrator')
ALTER TABLE [dbo].[Administrator] ADD [Email] [VarChar] (50) NOT NULL 
if exists(select * from sys.objects where name = 'Administrator' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'FirstName' and o.name = 'Administrator')
ALTER TABLE [dbo].[Administrator] ADD [FirstName] [VarChar] (50) NOT NULL 
if exists(select * from sys.objects where name = 'Administrator' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'LastIpAddress' and o.name = 'Administrator')
ALTER TABLE [dbo].[Administrator] ADD [LastIpAddress] [VarChar] (15) NOT NULL CONSTRAINT [DF__ADMINISTRATOR_LASTIPADDRESS] DEFAULT ('0.0.0.0')
if exists(select * from sys.objects where name = 'Administrator' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'LastName' and o.name = 'Administrator')
ALTER TABLE [dbo].[Administrator] ADD [LastName] [VarChar] (50) NOT NULL 
if exists(select * from sys.objects where name = 'Administrator' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'Password' and o.name = 'Administrator')
ALTER TABLE [dbo].[Administrator] ADD [Password] [VarChar] (100) NOT NULL 
if exists(select * from sys.objects where name = 'Administrator' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'UserName' and o.name = 'Administrator')
ALTER TABLE [dbo].[Administrator] ADD [UserName] [VarChar] (50) NOT NULL 
GO
--TABLE [BodyType] ADD FIELDS
if exists(select * from sys.objects where name = 'BodyType' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'BodyTypeId' and o.name = 'BodyType')
ALTER TABLE [dbo].[BodyType] ADD [BodyTypeId] [Int] IDENTITY (1, 1) NOT NULL 
if exists(select * from sys.objects where name = 'BodyType' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'Name' and o.name = 'BodyType')
ALTER TABLE [dbo].[BodyType] ADD [Name] [VarChar] (50) NOT NULL 
GO
--TABLE [BulletPoint] ADD FIELDS
if exists(select * from sys.objects where name = 'BulletPoint' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'BulletPointId' and o.name = 'BulletPoint')
ALTER TABLE [dbo].[BulletPoint] ADD [BulletPointId] [Int] IDENTITY (1, 1) NOT NULL 
if exists(select * from sys.objects where name = 'BulletPoint' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ListingId' and o.name = 'BulletPoint')
ALTER TABLE [dbo].[BulletPoint] ADD [ListingId] [Int] NOT NULL 
if exists(select * from sys.objects where name = 'BulletPoint' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'Text' and o.name = 'BulletPoint')
ALTER TABLE [dbo].[BulletPoint] ADD [Text] [VarChar] (500) NOT NULL 
GO
--TABLE [City] ADD FIELDS
if exists(select * from sys.objects where name = 'City' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'CityId' and o.name = 'City')
ALTER TABLE [dbo].[City] ADD [CityId] [Int] IDENTITY (1, 1) NOT NULL 
if exists(select * from sys.objects where name = 'City' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'Name' and o.name = 'City')
ALTER TABLE [dbo].[City] ADD [Name] [VarChar] (100) NOT NULL 
if exists(select * from sys.objects where name = 'City' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'StateId' and o.name = 'City')
ALTER TABLE [dbo].[City] ADD [StateId] [Int] NOT NULL 
GO
--TABLE [CityZip] ADD FIELDS
if exists(select * from sys.objects where name = 'CityZip' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'CityId' and o.name = 'CityZip')
ALTER TABLE [dbo].[CityZip] ADD [CityId] [Int] NOT NULL 
if exists(select * from sys.objects where name = 'CityZip' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ZipId' and o.name = 'CityZip')
ALTER TABLE [dbo].[CityZip] ADD [ZipId] [Int] NOT NULL 
GO
--TABLE [Color] ADD FIELDS
if exists(select * from sys.objects where name = 'Color' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ColorId' and o.name = 'Color')
ALTER TABLE [dbo].[Color] ADD [ColorId] [Int] IDENTITY (1, 1) NOT NULL 
if exists(select * from sys.objects where name = 'Color' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'Name' and o.name = 'Color')
ALTER TABLE [dbo].[Color] ADD [Name] [VarChar] (50) NOT NULL 
GO
--TABLE [Condition] ADD FIELDS
if exists(select * from sys.objects where name = 'Condition' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ConditionId' and o.name = 'Condition')
ALTER TABLE [dbo].[Condition] ADD [ConditionId] [Int] IDENTITY (1, 1) NOT NULL 
if exists(select * from sys.objects where name = 'Condition' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'Name' and o.name = 'Condition')
ALTER TABLE [dbo].[Condition] ADD [Name] [VarChar] (50) NULL 
GO
--TABLE [ConfigSetting] ADD FIELDS
if exists(select * from sys.objects where name = 'ConfigSetting' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ID' and o.name = 'ConfigSetting')
ALTER TABLE [dbo].[ConfigSetting] ADD [ID] [Int] IDENTITY (1, 1) NOT NULL 
if exists(select * from sys.objects where name = 'ConfigSetting' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'Name' and o.name = 'ConfigSetting')
ALTER TABLE [dbo].[ConfigSetting] ADD [Name] [VarChar] (50) NOT NULL 
if exists(select * from sys.objects where name = 'ConfigSetting' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'Value' and o.name = 'ConfigSetting')
ALTER TABLE [dbo].[ConfigSetting] ADD [Value] [VarChar] (100) NOT NULL 
GO
--TABLE [Dealer] ADD FIELDS
if exists(select * from sys.objects where name = 'Dealer' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'CompanyName' and o.name = 'Dealer')
ALTER TABLE [dbo].[Dealer] ADD [CompanyName] [VarChar] (50) NOT NULL 
if exists(select * from sys.objects where name = 'Dealer' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'Directions' and o.name = 'Dealer')
ALTER TABLE [dbo].[Dealer] ADD [Directions] [VarChar] (500) NULL 
if exists(select * from sys.objects where name = 'Dealer' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'MetroId' and o.name = 'Dealer')
ALTER TABLE [dbo].[Dealer] ADD [MetroId] [Int] NULL 
if exists(select * from sys.objects where name = 'Dealer' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'UserId' and o.name = 'Dealer')
ALTER TABLE [dbo].[Dealer] ADD [UserId] [Int] NOT NULL 
GO
--TABLE [Feature] ADD FIELDS
if exists(select * from sys.objects where name = 'Feature' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'FeatureId' and o.name = 'Feature')
ALTER TABLE [dbo].[Feature] ADD [FeatureId] [Int] IDENTITY (1, 1) NOT NULL 
if exists(select * from sys.objects where name = 'Feature' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'Name' and o.name = 'Feature')
ALTER TABLE [dbo].[Feature] ADD [Name] [VarChar] (50) NOT NULL 
GO
--TABLE [FuelType] ADD FIELDS
if exists(select * from sys.objects where name = 'FuelType' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'FuelTypeId' and o.name = 'FuelType')
ALTER TABLE [dbo].[FuelType] ADD [FuelTypeId] [Int] IDENTITY (1, 1) NOT NULL 
if exists(select * from sys.objects where name = 'FuelType' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'Name' and o.name = 'FuelType')
ALTER TABLE [dbo].[FuelType] ADD [Name] [VarChar] (50) NOT NULL 
GO
--TABLE [Listing] ADD FIELDS
if exists(select * from sys.objects where name = 'Listing' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'Active' and o.name = 'Listing')
ALTER TABLE [dbo].[Listing] ADD [Active] [Bit] NOT NULL CONSTRAINT [DF__LISTING_ACTIVE] DEFAULT (1)
if exists(select * from sys.objects where name = 'Listing' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'BodyTypeId' and o.name = 'Listing')
ALTER TABLE [dbo].[Listing] ADD [BodyTypeId] [Int] NULL 
if exists(select * from sys.objects where name = 'Listing' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ColorExtId' and o.name = 'Listing')
ALTER TABLE [dbo].[Listing] ADD [ColorExtId] [Int] NOT NULL 
if exists(select * from sys.objects where name = 'Listing' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ColorIntId' and o.name = 'Listing')
ALTER TABLE [dbo].[Listing] ADD [ColorIntId] [Int] NOT NULL 
if exists(select * from sys.objects where name = 'Listing' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ConditionId' and o.name = 'Listing')
ALTER TABLE [dbo].[Listing] ADD [ConditionId] [Int] NULL 
if exists(select * from sys.objects where name = 'Listing' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'Cylinders' and o.name = 'Listing')
ALTER TABLE [dbo].[Listing] ADD [Cylinders] [Int] NULL 
if exists(select * from sys.objects where name = 'Listing' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'Description' and o.name = 'Listing')
ALTER TABLE [dbo].[Listing] ADD [Description] [VarChar] (1000) NULL 
if exists(select * from sys.objects where name = 'Listing' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'Disclaimer' and o.name = 'Listing')
ALTER TABLE [dbo].[Listing] ADD [Disclaimer] [VarChar] (5000) NULL 
if exists(select * from sys.objects where name = 'Listing' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'Doors' and o.name = 'Listing')
ALTER TABLE [dbo].[Listing] ADD [Doors] [Int] NULL 
if exists(select * from sys.objects where name = 'Listing' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'Engine' and o.name = 'Listing')
ALTER TABLE [dbo].[Listing] ADD [Engine] [VarChar] (100) NULL 
if exists(select * from sys.objects where name = 'Listing' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ExpirationDate' and o.name = 'Listing')
ALTER TABLE [dbo].[Listing] ADD [ExpirationDate] [DateTime] NOT NULL CONSTRAINT [DF__LISTING_EXPIRATIONDATE] DEFAULT (getdate())
if exists(select * from sys.objects where name = 'Listing' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'FuelTypeId' and o.name = 'Listing')
ALTER TABLE [dbo].[Listing] ADD [FuelTypeId] [Int] NULL 
if exists(select * from sys.objects where name = 'Listing' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'Invoice' and o.name = 'Listing')
ALTER TABLE [dbo].[Listing] ADD [Invoice] [Int] NULL 
if exists(select * from sys.objects where name = 'Listing' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'IsFeatured' and o.name = 'Listing')
ALTER TABLE [dbo].[Listing] ADD [IsFeatured] [Bit] NULL 
if exists(select * from sys.objects where name = 'Listing' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ListDate' and o.name = 'Listing')
ALTER TABLE [dbo].[Listing] ADD [ListDate] [DateTime] NULL 
if exists(select * from sys.objects where name = 'Listing' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ListingId' and o.name = 'Listing')
ALTER TABLE [dbo].[Listing] ADD [ListingId] [Int] IDENTITY (1, 1) NOT NULL 
if exists(select * from sys.objects where name = 'Listing' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'MakeModelId' and o.name = 'Listing')
ALTER TABLE [dbo].[Listing] ADD [MakeModelId] [Int] NOT NULL 
if exists(select * from sys.objects where name = 'Listing' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'MetroId' and o.name = 'Listing')
ALTER TABLE [dbo].[Listing] ADD [MetroId] [Int] NULL 
if exists(select * from sys.objects where name = 'Listing' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'Mileage' and o.name = 'Listing')
ALTER TABLE [dbo].[Listing] ADD [Mileage] [Int] NOT NULL 
if exists(select * from sys.objects where name = 'Listing' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'Price' and o.name = 'Listing')
ALTER TABLE [dbo].[Listing] ADD [Price] [Int] NOT NULL 
if exists(select * from sys.objects where name = 'Listing' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'StockNumber' and o.name = 'Listing')
ALTER TABLE [dbo].[Listing] ADD [StockNumber] [VarChar] (50) NULL 
if exists(select * from sys.objects where name = 'Listing' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'Title' and o.name = 'Listing')
ALTER TABLE [dbo].[Listing] ADD [Title] [VarChar] (100) NULL 
if exists(select * from sys.objects where name = 'Listing' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'TransmissionId' and o.name = 'Listing')
ALTER TABLE [dbo].[Listing] ADD [TransmissionId] [Int] NULL 
if exists(select * from sys.objects where name = 'Listing' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'TrimLevel' and o.name = 'Listing')
ALTER TABLE [dbo].[Listing] ADD [TrimLevel] [VarChar] (10) NULL 
if exists(select * from sys.objects where name = 'Listing' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'UserId' and o.name = 'Listing')
ALTER TABLE [dbo].[Listing] ADD [UserId] [Int] NOT NULL 
if exists(select * from sys.objects where name = 'Listing' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'Vin' and o.name = 'Listing')
ALTER TABLE [dbo].[Listing] ADD [Vin] [VarChar] (50) NULL 
if exists(select * from sys.objects where name = 'Listing' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'Year' and o.name = 'Listing')
ALTER TABLE [dbo].[Listing] ADD [Year] [Int] NOT NULL 
GO
--TABLE [ListingFeature] ADD FIELDS
if exists(select * from sys.objects where name = 'ListingFeature' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'FeatureId' and o.name = 'ListingFeature')
ALTER TABLE [dbo].[ListingFeature] ADD [FeatureId] [Int] NOT NULL 
if exists(select * from sys.objects where name = 'ListingFeature' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ListingId' and o.name = 'ListingFeature')
ALTER TABLE [dbo].[ListingFeature] ADD [ListingId] [Int] NOT NULL 
GO
--TABLE [ListingImage] ADD FIELDS
if exists(select * from sys.objects where name = 'ListingImage' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'FileName' and o.name = 'ListingImage')
ALTER TABLE [dbo].[ListingImage] ADD [FileName] [VarChar] (100) NOT NULL 
if exists(select * from sys.objects where name = 'ListingImage' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ListingId' and o.name = 'ListingImage')
ALTER TABLE [dbo].[ListingImage] ADD [ListingId] [Int] NOT NULL 
if exists(select * from sys.objects where name = 'ListingImage' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ListingImageId' and o.name = 'ListingImage')
ALTER TABLE [dbo].[ListingImage] ADD [ListingImageId] [Int] IDENTITY (1, 1) NOT NULL 
if exists(select * from sys.objects where name = 'ListingImage' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'SortOrder' and o.name = 'ListingImage')
ALTER TABLE [dbo].[ListingImage] ADD [SortOrder] [Int] NULL 
GO
--TABLE [ListingPremium] ADD FIELDS
if exists(select * from sys.objects where name = 'ListingPremium' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'Active' and o.name = 'ListingPremium')
ALTER TABLE [dbo].[ListingPremium] ADD [Active] [Bit] NOT NULL CONSTRAINT [DF__LISTINGPREMIUM_ACTIVE] DEFAULT (1)
if exists(select * from sys.objects where name = 'ListingPremium' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'CityName' and o.name = 'ListingPremium')
ALTER TABLE [dbo].[ListingPremium] ADD [CityName] [VarChar] (50) NOT NULL 
if exists(select * from sys.objects where name = 'ListingPremium' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ExpirationDate' and o.name = 'ListingPremium')
ALTER TABLE [dbo].[ListingPremium] ADD [ExpirationDate] [DateTime] NOT NULL 
if exists(select * from sys.objects where name = 'ListingPremium' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ListingId' and o.name = 'ListingPremium')
ALTER TABLE [dbo].[ListingPremium] ADD [ListingId] [Int] NOT NULL 
if exists(select * from sys.objects where name = 'ListingPremium' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ListingPremiumId' and o.name = 'ListingPremium')
ALTER TABLE [dbo].[ListingPremium] ADD [ListingPremiumId] [Int] IDENTITY (1, 1) NOT NULL 
if exists(select * from sys.objects where name = 'ListingPremium' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'StartDate' and o.name = 'ListingPremium')
ALTER TABLE [dbo].[ListingPremium] ADD [StartDate] [DateTime] NOT NULL 
if exists(select * from sys.objects where name = 'ListingPremium' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'StateId' and o.name = 'ListingPremium')
ALTER TABLE [dbo].[ListingPremium] ADD [StateId] [Int] NOT NULL 
GO
--TABLE [ListingSaved] ADD FIELDS
if exists(select * from sys.objects where name = 'ListingSaved' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ListingId' and o.name = 'ListingSaved')
ALTER TABLE [dbo].[ListingSaved] ADD [ListingId] [Int] NOT NULL 
if exists(select * from sys.objects where name = 'ListingSaved' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'UserId' and o.name = 'ListingSaved')
ALTER TABLE [dbo].[ListingSaved] ADD [UserId] [Int] NOT NULL 
GO
--TABLE [ListingView] ADD FIELDS
if exists(select * from sys.objects where name = 'ListingView' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ListingId' and o.name = 'ListingView')
ALTER TABLE [dbo].[ListingView] ADD [ListingId] [Int] NOT NULL 
if exists(select * from sys.objects where name = 'ListingView' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ListingViewId' and o.name = 'ListingView')
ALTER TABLE [dbo].[ListingView] ADD [ListingViewId] [Int] IDENTITY (1, 1) NOT NULL 
GO
--TABLE [Make] ADD FIELDS
if exists(select * from sys.objects where name = 'Make' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'MakeId' and o.name = 'Make')
ALTER TABLE [dbo].[Make] ADD [MakeId] [Int] IDENTITY (1, 1) NOT NULL 
if exists(select * from sys.objects where name = 'Make' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'Name' and o.name = 'Make')
ALTER TABLE [dbo].[Make] ADD [Name] [VarChar] (50) NOT NULL 
GO
--TABLE [MakeModel] ADD FIELDS
if exists(select * from sys.objects where name = 'MakeModel' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'MakeId' and o.name = 'MakeModel')
ALTER TABLE [dbo].[MakeModel] ADD [MakeId] [Int] NOT NULL 
if exists(select * from sys.objects where name = 'MakeModel' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'MakeModelId' and o.name = 'MakeModel')
ALTER TABLE [dbo].[MakeModel] ADD [MakeModelId] [Int] IDENTITY (1, 1) NOT NULL 
if exists(select * from sys.objects where name = 'MakeModel' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ModelId' and o.name = 'MakeModel')
ALTER TABLE [dbo].[MakeModel] ADD [ModelId] [Int] NOT NULL 
GO
--TABLE [Metro] ADD FIELDS
if exists(select * from sys.objects where name = 'Metro' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'IsPopular' and o.name = 'Metro')
ALTER TABLE [dbo].[Metro] ADD [IsPopular] [VarChar] (1) NOT NULL CONSTRAINT [DF__METRO_ISPOPULAR] DEFAULT ('0')
if exists(select * from sys.objects where name = 'Metro' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'MetroId' and o.name = 'Metro')
ALTER TABLE [dbo].[Metro] ADD [MetroId] [Int] IDENTITY (1, 1) NOT NULL 
if exists(select * from sys.objects where name = 'Metro' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'Name' and o.name = 'Metro')
ALTER TABLE [dbo].[Metro] ADD [Name] [VarChar] (50) NOT NULL 
GO
--TABLE [MetroState] ADD FIELDS
if exists(select * from sys.objects where name = 'MetroState' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'MetroId' and o.name = 'MetroState')
ALTER TABLE [dbo].[MetroState] ADD [MetroId] [Int] NOT NULL 
if exists(select * from sys.objects where name = 'MetroState' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'StateId' and o.name = 'MetroState')
ALTER TABLE [dbo].[MetroState] ADD [StateId] [Int] NOT NULL 
GO
--TABLE [MetroZip] ADD FIELDS
if exists(select * from sys.objects where name = 'MetroZip' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'MetroId' and o.name = 'MetroZip')
ALTER TABLE [dbo].[MetroZip] ADD [MetroId] [Int] NOT NULL 
if exists(select * from sys.objects where name = 'MetroZip' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ZipId' and o.name = 'MetroZip')
ALTER TABLE [dbo].[MetroZip] ADD [ZipId] [Int] NOT NULL 
GO
--TABLE [Model] ADD FIELDS
if exists(select * from sys.objects where name = 'Model' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ModelId' and o.name = 'Model')
ALTER TABLE [dbo].[Model] ADD [ModelId] [Int] IDENTITY (1, 1) NOT NULL 
if exists(select * from sys.objects where name = 'Model' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'MpgCity' and o.name = 'Model')
ALTER TABLE [dbo].[Model] ADD [MpgCity] [Int] NULL 
if exists(select * from sys.objects where name = 'Model' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'MpgHighway' and o.name = 'Model')
ALTER TABLE [dbo].[Model] ADD [MpgHighway] [Int] NULL 
if exists(select * from sys.objects where name = 'Model' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'Name' and o.name = 'Model')
ALTER TABLE [dbo].[Model] ADD [Name] [VarChar] (50) NOT NULL 
GO
--TABLE [SearchSaved] ADD FIELDS
if exists(select * from sys.objects where name = 'SearchSaved' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'Location' and o.name = 'SearchSaved')
ALTER TABLE [dbo].[SearchSaved] ADD [Location] [VarChar] (100) NULL 
if exists(select * from sys.objects where name = 'SearchSaved' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'Name' and o.name = 'SearchSaved')
ALTER TABLE [dbo].[SearchSaved] ADD [Name] [VarChar] (50) NOT NULL 
if exists(select * from sys.objects where name = 'SearchSaved' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'Radius' and o.name = 'SearchSaved')
ALTER TABLE [dbo].[SearchSaved] ADD [Radius] [Int] NULL 
if exists(select * from sys.objects where name = 'SearchSaved' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'SearchSavedId' and o.name = 'SearchSaved')
ALTER TABLE [dbo].[SearchSaved] ADD [SearchSavedId] [Int] IDENTITY (1, 1) NOT NULL 
if exists(select * from sys.objects where name = 'SearchSaved' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'Text' and o.name = 'SearchSaved')
ALTER TABLE [dbo].[SearchSaved] ADD [Text] [VarChar] (100) NULL 
if exists(select * from sys.objects where name = 'SearchSaved' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'UserId' and o.name = 'SearchSaved')
ALTER TABLE [dbo].[SearchSaved] ADD [UserId] [Int] NOT NULL 
GO
--TABLE [SearchSavedCriteria] ADD FIELDS
if exists(select * from sys.objects where name = 'SearchSavedCriteria' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'Didx' and o.name = 'SearchSavedCriteria')
ALTER TABLE [dbo].[SearchSavedCriteria] ADD [Didx] [Int] NOT NULL 
if exists(select * from sys.objects where name = 'SearchSavedCriteria' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'Dvidx' and o.name = 'SearchSavedCriteria')
ALTER TABLE [dbo].[SearchSavedCriteria] ADD [Dvidx] [Int] NOT NULL 
if exists(select * from sys.objects where name = 'SearchSavedCriteria' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'SearchSavedCriteriaId' and o.name = 'SearchSavedCriteria')
ALTER TABLE [dbo].[SearchSavedCriteria] ADD [SearchSavedCriteriaId] [Int] IDENTITY (1, 1) NOT NULL 
if exists(select * from sys.objects where name = 'SearchSavedCriteria' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'SearchSavedId' and o.name = 'SearchSavedCriteria')
ALTER TABLE [dbo].[SearchSavedCriteria] ADD [SearchSavedId] [Int] NOT NULL 
GO
--TABLE [State] ADD FIELDS
if exists(select * from sys.objects where name = 'State' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'Abbr' and o.name = 'State')
ALTER TABLE [dbo].[State] ADD [Abbr] [VarChar] (2) NOT NULL 
if exists(select * from sys.objects where name = 'State' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'Description' and o.name = 'State')
ALTER TABLE [dbo].[State] ADD [Description] [VarChar] (4000) NOT NULL 
if exists(select * from sys.objects where name = 'State' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'Name' and o.name = 'State')
ALTER TABLE [dbo].[State] ADD [Name] [VarChar] (50) NOT NULL 
if exists(select * from sys.objects where name = 'State' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'StateId' and o.name = 'State')
ALTER TABLE [dbo].[State] ADD [StateId] [Int] IDENTITY (1, 1) NOT NULL 
GO
--TABLE [Transmission] ADD FIELDS
if exists(select * from sys.objects where name = 'Transmission' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'Name' and o.name = 'Transmission')
ALTER TABLE [dbo].[Transmission] ADD [Name] [VarChar] (50) NOT NULL 
if exists(select * from sys.objects where name = 'Transmission' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'TransmissionId' and o.name = 'Transmission')
ALTER TABLE [dbo].[Transmission] ADD [TransmissionId] [Int] IDENTITY (1, 1) NOT NULL 
GO
--TABLE [UserAccount] ADD FIELDS
if exists(select * from sys.objects where name = 'UserAccount' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'AcceptedAdvertTerms' and o.name = 'UserAccount')
ALTER TABLE [dbo].[UserAccount] ADD [AcceptedAdvertTerms] [Bit] NOT NULL CONSTRAINT [DF__USERACCOUNT_ACCEPTEDADVERTTERMS] DEFAULT (0)
if exists(select * from sys.objects where name = 'UserAccount' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'Active' and o.name = 'UserAccount')
ALTER TABLE [dbo].[UserAccount] ADD [Active] [Bit] NOT NULL CONSTRAINT [DF__USERACCOUNT_ACTIVE] DEFAULT (1)
if exists(select * from sys.objects where name = 'UserAccount' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'Address1' and o.name = 'UserAccount')
ALTER TABLE [dbo].[UserAccount] ADD [Address1] [VarChar] (150) NULL 
if exists(select * from sys.objects where name = 'UserAccount' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'Address2' and o.name = 'UserAccount')
ALTER TABLE [dbo].[UserAccount] ADD [Address2] [VarChar] (150) NULL 
if exists(select * from sys.objects where name = 'UserAccount' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'AlertFrequency' and o.name = 'UserAccount')
ALTER TABLE [dbo].[UserAccount] ADD [AlertFrequency] [Int] NOT NULL CONSTRAINT [DF__USERACCOUNT_ALERTFREQUENCY] DEFAULT (7)
if exists(select * from sys.objects where name = 'UserAccount' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'AlertSent' and o.name = 'UserAccount')
ALTER TABLE [dbo].[UserAccount] ADD [AlertSent] [DateTime] NULL CONSTRAINT [DF__USERACCOUNT_ALERTSENT] DEFAULT (getdate())
if exists(select * from sys.objects where name = 'UserAccount' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'City' and o.name = 'UserAccount')
ALTER TABLE [dbo].[UserAccount] ADD [City] [VarChar] (100) NULL 
if exists(select * from sys.objects where name = 'UserAccount' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'Description' and o.name = 'UserAccount')
ALTER TABLE [dbo].[UserAccount] ADD [Description] [NText] NULL 
if exists(select * from sys.objects where name = 'UserAccount' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'Email' and o.name = 'UserAccount')
ALTER TABLE [dbo].[UserAccount] ADD [Email] [VarChar] (175) NOT NULL 
if exists(select * from sys.objects where name = 'UserAccount' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'FirstName' and o.name = 'UserAccount')
ALTER TABLE [dbo].[UserAccount] ADD [FirstName] [VarChar] (100) NOT NULL 
if exists(select * from sys.objects where name = 'UserAccount' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'HomePhone' and o.name = 'UserAccount')
ALTER TABLE [dbo].[UserAccount] ADD [HomePhone] [VarChar] (20) NULL 
if exists(select * from sys.objects where name = 'UserAccount' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'LastName' and o.name = 'UserAccount')
ALTER TABLE [dbo].[UserAccount] ADD [LastName] [VarChar] (100) NOT NULL 
if exists(select * from sys.objects where name = 'UserAccount' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'Latitude' and o.name = 'UserAccount')
ALTER TABLE [dbo].[UserAccount] ADD [Latitude] [Float] NULL 
if exists(select * from sys.objects where name = 'UserAccount' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'Longitude' and o.name = 'UserAccount')
ALTER TABLE [dbo].[UserAccount] ADD [Longitude] [Float] NULL 
if exists(select * from sys.objects where name = 'UserAccount' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'MobilePhone' and o.name = 'UserAccount')
ALTER TABLE [dbo].[UserAccount] ADD [MobilePhone] [VarChar] (20) NULL 
if exists(select * from sys.objects where name = 'UserAccount' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'OfficeFax' and o.name = 'UserAccount')
ALTER TABLE [dbo].[UserAccount] ADD [OfficeFax] [VarChar] (20) NULL 
if exists(select * from sys.objects where name = 'UserAccount' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'OfficePhone' and o.name = 'UserAccount')
ALTER TABLE [dbo].[UserAccount] ADD [OfficePhone] [VarChar] (20) NULL 
if exists(select * from sys.objects where name = 'UserAccount' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'OfficePhoneExt' and o.name = 'UserAccount')
ALTER TABLE [dbo].[UserAccount] ADD [OfficePhoneExt] [VarChar] (10) NULL 
if exists(select * from sys.objects where name = 'UserAccount' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'Password' and o.name = 'UserAccount')
ALTER TABLE [dbo].[UserAccount] ADD [Password] [VarChar] (100) NOT NULL 
if exists(select * from sys.objects where name = 'UserAccount' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'StateId' and o.name = 'UserAccount')
ALTER TABLE [dbo].[UserAccount] ADD [StateId] [Int] NOT NULL 
if exists(select * from sys.objects where name = 'UserAccount' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'UserId' and o.name = 'UserAccount')
ALTER TABLE [dbo].[UserAccount] ADD [UserId] [Int] IDENTITY (1, 1) NOT NULL 
if exists(select * from sys.objects where name = 'UserAccount' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'UserTypeId' and o.name = 'UserAccount')
ALTER TABLE [dbo].[UserAccount] ADD [UserTypeId] [Int] NOT NULL 
if exists(select * from sys.objects where name = 'UserAccount' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ZipId' and o.name = 'UserAccount')
ALTER TABLE [dbo].[UserAccount] ADD [ZipId] [Int] NULL 
GO
--TABLE [UserLoginHistory] ADD FIELDS
if exists(select * from sys.objects where name = 'UserLoginHistory' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'BrowserAgent' and o.name = 'UserLoginHistory')
ALTER TABLE [dbo].[UserLoginHistory] ADD [BrowserAgent] [VarChar] (255) NULL 
if exists(select * from sys.objects where name = 'UserLoginHistory' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'IpAddress' and o.name = 'UserLoginHistory')
ALTER TABLE [dbo].[UserLoginHistory] ADD [IpAddress] [VarChar] (15) NOT NULL CONSTRAINT [DF__USERLOGINHISTORY_IPADDRESS] DEFAULT ('000.000.000.000')
if exists(select * from sys.objects where name = 'UserLoginHistory' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'UserId' and o.name = 'UserLoginHistory')
ALTER TABLE [dbo].[UserLoginHistory] ADD [UserId] [Int] NOT NULL 
if exists(select * from sys.objects where name = 'UserLoginHistory' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'UserLoginHistoryId' and o.name = 'UserLoginHistory')
ALTER TABLE [dbo].[UserLoginHistory] ADD [UserLoginHistoryId] [Int] IDENTITY (1, 1) NOT NULL 
GO
--TABLE [UserType] ADD FIELDS
if exists(select * from sys.objects where name = 'UserType' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'Active' and o.name = 'UserType')
ALTER TABLE [dbo].[UserType] ADD [Active] [Bit] NOT NULL CONSTRAINT [DF__USERTYPE_ACTIVE] DEFAULT (1)
if exists(select * from sys.objects where name = 'UserType' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'Name' and o.name = 'UserType')
ALTER TABLE [dbo].[UserType] ADD [Name] [VarChar] (50) NOT NULL 
if exists(select * from sys.objects where name = 'UserType' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'UserTypeId' and o.name = 'UserType')
ALTER TABLE [dbo].[UserType] ADD [UserTypeId] [Int] IDENTITY (1, 1) NOT NULL 
GO
--TABLE [VistorContact] ADD FIELDS
if exists(select * from sys.objects where name = 'VistorContact' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'Email' and o.name = 'VistorContact')
ALTER TABLE [dbo].[VistorContact] ADD [Email] [VarChar] (128) NULL 
if exists(select * from sys.objects where name = 'VistorContact' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'IpAddress' and o.name = 'VistorContact')
ALTER TABLE [dbo].[VistorContact] ADD [IpAddress] [Char] (15) NOT NULL CONSTRAINT [DF__VISTORCONTACT_IPADDRESS] DEFAULT ('000.000.000.000')
if exists(select * from sys.objects where name = 'VistorContact' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'IsHandled' and o.name = 'VistorContact')
ALTER TABLE [dbo].[VistorContact] ADD [IsHandled] [Bit] NOT NULL CONSTRAINT [DF__VISTORCONTACT_ISHANDLED] DEFAULT (0)
if exists(select * from sys.objects where name = 'VistorContact' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'Message' and o.name = 'VistorContact')
ALTER TABLE [dbo].[VistorContact] ADD [Message] [Text] NOT NULL 
if exists(select * from sys.objects where name = 'VistorContact' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'Name' and o.name = 'VistorContact')
ALTER TABLE [dbo].[VistorContact] ADD [Name] [VarChar] (100) NULL 
if exists(select * from sys.objects where name = 'VistorContact' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'Phone' and o.name = 'VistorContact')
ALTER TABLE [dbo].[VistorContact] ADD [Phone] [VarChar] (15) NULL 
if exists(select * from sys.objects where name = 'VistorContact' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'UserId' and o.name = 'VistorContact')
ALTER TABLE [dbo].[VistorContact] ADD [UserId] [Int] NULL 
if exists(select * from sys.objects where name = 'VistorContact' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'VisitorContactId' and o.name = 'VistorContact')
ALTER TABLE [dbo].[VistorContact] ADD [VisitorContactId] [Int] IDENTITY (1, 1) NOT NULL 
GO
--TABLE [Zip] ADD FIELDS
if exists(select * from sys.objects where name = 'Zip' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'Latitude' and o.name = 'Zip')
ALTER TABLE [dbo].[Zip] ADD [Latitude] [Float] NULL 
if exists(select * from sys.objects where name = 'Zip' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'Longitude' and o.name = 'Zip')
ALTER TABLE [dbo].[Zip] ADD [Longitude] [Float] NULL 
if exists(select * from sys.objects where name = 'Zip' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'Name' and o.name = 'Zip')
ALTER TABLE [dbo].[Zip] ADD [Name] [VarChar] (10) NOT NULL 
if exists(select * from sys.objects where name = 'Zip' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'StateId' and o.name = 'Zip')
ALTER TABLE [dbo].[Zip] ADD [StateId] [Int] NULL 
if exists(select * from sys.objects where name = 'Zip' and type = 'U') AND not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ZipId' and o.name = 'Zip')
ALTER TABLE [dbo].[Zip] ADD [ZipId] [Int] IDENTITY (1, 1) NOT NULL 
GO
--##SECTION END [FIELD CREATE]

--##SECTION BEGIN [AUDIT TRAIL CREATE]

--APPEND AUDIT TRAIL CREATE FOR TABLE [Administrator]
if exists(select * from sys.objects where name = 'Administrator' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'CreatedBy' and o.name = 'Administrator')
ALTER TABLE [dbo].[Administrator] ADD [CreatedBy] [Varchar] (50) NULL
if exists(select * from sys.objects where name = 'Administrator' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'CreatedDate' and o.name = 'Administrator')
ALTER TABLE [dbo].[Administrator] ADD [CreatedDate] [DateTime] CONSTRAINT [DF__ADMINISTRATOR_CREATEDDATE] DEFAULT getdate() NULL

--APPEND AUDIT TRAIL MODIFY FOR TABLE [Administrator]
if exists(select * from sys.objects where name = 'Administrator' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ModifiedBy' and o.name = 'Administrator')
ALTER TABLE [dbo].[Administrator] ADD [ModifiedBy] [Varchar] (50) NULL
if exists(select * from sys.objects where name = 'Administrator' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ModifiedDate' and o.name = 'Administrator')
ALTER TABLE [dbo].[Administrator] ADD [ModifiedDate] [DateTime] CONSTRAINT [DF__ADMINISTRATOR_MODIFIEDDATE] DEFAULT getdate() NULL

--APPEND AUDIT TRAIL TIMESTAMP FOR TABLE [Administrator]
if exists(select * from sys.objects where name = 'Administrator' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'TimeStamp' and o.name = 'Administrator')
ALTER TABLE [dbo].[Administrator] ADD [TimeStamp] [timestamp] NOT NULL

GO

--APPEND AUDIT TRAIL CREATE FOR TABLE [BodyType]
if exists(select * from sys.objects where name = 'BodyType' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'CreatedBy' and o.name = 'BodyType')
ALTER TABLE [dbo].[BodyType] ADD [CreatedBy] [Varchar] (50) NULL
if exists(select * from sys.objects where name = 'BodyType' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'CreatedDate' and o.name = 'BodyType')
ALTER TABLE [dbo].[BodyType] ADD [CreatedDate] [DateTime] CONSTRAINT [DF__BODYTYPE_CREATEDDATE] DEFAULT getdate() NULL

--APPEND AUDIT TRAIL MODIFY FOR TABLE [BodyType]
if exists(select * from sys.objects where name = 'BodyType' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ModifiedBy' and o.name = 'BodyType')
ALTER TABLE [dbo].[BodyType] ADD [ModifiedBy] [Varchar] (50) NULL
if exists(select * from sys.objects where name = 'BodyType' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ModifiedDate' and o.name = 'BodyType')
ALTER TABLE [dbo].[BodyType] ADD [ModifiedDate] [DateTime] CONSTRAINT [DF__BODYTYPE_MODIFIEDDATE] DEFAULT getdate() NULL

--APPEND AUDIT TRAIL TIMESTAMP FOR TABLE [BodyType]
if exists(select * from sys.objects where name = 'BodyType' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'TimeStamp' and o.name = 'BodyType')
ALTER TABLE [dbo].[BodyType] ADD [TimeStamp] [timestamp] NOT NULL

GO

--APPEND AUDIT TRAIL CREATE FOR TABLE [BulletPoint]
if exists(select * from sys.objects where name = 'BulletPoint' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'CreatedBy' and o.name = 'BulletPoint')
ALTER TABLE [dbo].[BulletPoint] ADD [CreatedBy] [Varchar] (50) NULL
if exists(select * from sys.objects where name = 'BulletPoint' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'CreatedDate' and o.name = 'BulletPoint')
ALTER TABLE [dbo].[BulletPoint] ADD [CreatedDate] [DateTime] CONSTRAINT [DF__BULLETPOINT_CREATEDDATE] DEFAULT getdate() NULL

--APPEND AUDIT TRAIL MODIFY FOR TABLE [BulletPoint]
if exists(select * from sys.objects where name = 'BulletPoint' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ModifiedBy' and o.name = 'BulletPoint')
ALTER TABLE [dbo].[BulletPoint] ADD [ModifiedBy] [Varchar] (50) NULL
if exists(select * from sys.objects where name = 'BulletPoint' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ModifiedDate' and o.name = 'BulletPoint')
ALTER TABLE [dbo].[BulletPoint] ADD [ModifiedDate] [DateTime] CONSTRAINT [DF__BULLETPOINT_MODIFIEDDATE] DEFAULT getdate() NULL

--APPEND AUDIT TRAIL TIMESTAMP FOR TABLE [BulletPoint]
if exists(select * from sys.objects where name = 'BulletPoint' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'TimeStamp' and o.name = 'BulletPoint')
ALTER TABLE [dbo].[BulletPoint] ADD [TimeStamp] [timestamp] NOT NULL

GO

--APPEND AUDIT TRAIL CREATE FOR TABLE [City]
if exists(select * from sys.objects where name = 'City' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'CreatedBy' and o.name = 'City')
ALTER TABLE [dbo].[City] ADD [CreatedBy] [Varchar] (50) NULL
if exists(select * from sys.objects where name = 'City' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'CreatedDate' and o.name = 'City')
ALTER TABLE [dbo].[City] ADD [CreatedDate] [DateTime] CONSTRAINT [DF__CITY_CREATEDDATE] DEFAULT getdate() NULL

--APPEND AUDIT TRAIL MODIFY FOR TABLE [City]
if exists(select * from sys.objects where name = 'City' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ModifiedBy' and o.name = 'City')
ALTER TABLE [dbo].[City] ADD [ModifiedBy] [Varchar] (50) NULL
if exists(select * from sys.objects where name = 'City' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ModifiedDate' and o.name = 'City')
ALTER TABLE [dbo].[City] ADD [ModifiedDate] [DateTime] CONSTRAINT [DF__CITY_MODIFIEDDATE] DEFAULT getdate() NULL

--APPEND AUDIT TRAIL TIMESTAMP FOR TABLE [City]
if exists(select * from sys.objects where name = 'City' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'TimeStamp' and o.name = 'City')
ALTER TABLE [dbo].[City] ADD [TimeStamp] [timestamp] NOT NULL

GO

--APPEND AUDIT TRAIL CREATE FOR TABLE [Color]
if exists(select * from sys.objects where name = 'Color' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'CreatedBy' and o.name = 'Color')
ALTER TABLE [dbo].[Color] ADD [CreatedBy] [Varchar] (50) NULL
if exists(select * from sys.objects where name = 'Color' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'CreatedDate' and o.name = 'Color')
ALTER TABLE [dbo].[Color] ADD [CreatedDate] [DateTime] CONSTRAINT [DF__COLOR_CREATEDDATE] DEFAULT getdate() NULL

--APPEND AUDIT TRAIL MODIFY FOR TABLE [Color]
if exists(select * from sys.objects where name = 'Color' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ModifiedBy' and o.name = 'Color')
ALTER TABLE [dbo].[Color] ADD [ModifiedBy] [Varchar] (50) NULL
if exists(select * from sys.objects where name = 'Color' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ModifiedDate' and o.name = 'Color')
ALTER TABLE [dbo].[Color] ADD [ModifiedDate] [DateTime] CONSTRAINT [DF__COLOR_MODIFIEDDATE] DEFAULT getdate() NULL

--APPEND AUDIT TRAIL TIMESTAMP FOR TABLE [Color]
if exists(select * from sys.objects where name = 'Color' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'TimeStamp' and o.name = 'Color')
ALTER TABLE [dbo].[Color] ADD [TimeStamp] [timestamp] NOT NULL

GO

--APPEND AUDIT TRAIL CREATE FOR TABLE [Condition]
if exists(select * from sys.objects where name = 'Condition' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'CreatedBy' and o.name = 'Condition')
ALTER TABLE [dbo].[Condition] ADD [CreatedBy] [Varchar] (50) NULL
if exists(select * from sys.objects where name = 'Condition' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'CreatedDate' and o.name = 'Condition')
ALTER TABLE [dbo].[Condition] ADD [CreatedDate] [DateTime] CONSTRAINT [DF__CONDITION_CREATEDDATE] DEFAULT getdate() NULL

--APPEND AUDIT TRAIL MODIFY FOR TABLE [Condition]
if exists(select * from sys.objects where name = 'Condition' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ModifiedBy' and o.name = 'Condition')
ALTER TABLE [dbo].[Condition] ADD [ModifiedBy] [Varchar] (50) NULL
if exists(select * from sys.objects where name = 'Condition' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ModifiedDate' and o.name = 'Condition')
ALTER TABLE [dbo].[Condition] ADD [ModifiedDate] [DateTime] CONSTRAINT [DF__CONDITION_MODIFIEDDATE] DEFAULT getdate() NULL

--APPEND AUDIT TRAIL TIMESTAMP FOR TABLE [Condition]
if exists(select * from sys.objects where name = 'Condition' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'TimeStamp' and o.name = 'Condition')
ALTER TABLE [dbo].[Condition] ADD [TimeStamp] [timestamp] NOT NULL

GO

--APPEND AUDIT TRAIL CREATE FOR TABLE [ConfigSetting]
if exists(select * from sys.objects where name = 'ConfigSetting' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'CreatedBy' and o.name = 'ConfigSetting')
ALTER TABLE [dbo].[ConfigSetting] ADD [CreatedBy] [Varchar] (50) NULL
if exists(select * from sys.objects where name = 'ConfigSetting' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'CreatedDate' and o.name = 'ConfigSetting')
ALTER TABLE [dbo].[ConfigSetting] ADD [CreatedDate] [DateTime] CONSTRAINT [DF__CONFIGSETTING_CREATEDDATE] DEFAULT getdate() NULL

--APPEND AUDIT TRAIL MODIFY FOR TABLE [ConfigSetting]
if exists(select * from sys.objects where name = 'ConfigSetting' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ModifiedBy' and o.name = 'ConfigSetting')
ALTER TABLE [dbo].[ConfigSetting] ADD [ModifiedBy] [Varchar] (50) NULL
if exists(select * from sys.objects where name = 'ConfigSetting' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ModifiedDate' and o.name = 'ConfigSetting')
ALTER TABLE [dbo].[ConfigSetting] ADD [ModifiedDate] [DateTime] CONSTRAINT [DF__CONFIGSETTING_MODIFIEDDATE] DEFAULT getdate() NULL

--APPEND AUDIT TRAIL TIMESTAMP FOR TABLE [ConfigSetting]
if exists(select * from sys.objects where name = 'ConfigSetting' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'TimeStamp' and o.name = 'ConfigSetting')
ALTER TABLE [dbo].[ConfigSetting] ADD [TimeStamp] [timestamp] NOT NULL

GO

--APPEND AUDIT TRAIL CREATE FOR TABLE [Dealer]
if exists(select * from sys.objects where name = 'Dealer' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'CreatedBy' and o.name = 'Dealer')
ALTER TABLE [dbo].[Dealer] ADD [CreatedBy] [Varchar] (50) NULL
if exists(select * from sys.objects where name = 'Dealer' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'CreatedDate' and o.name = 'Dealer')
ALTER TABLE [dbo].[Dealer] ADD [CreatedDate] [DateTime] CONSTRAINT [DF__DEALER_CREATEDDATE] DEFAULT getdate() NULL

--APPEND AUDIT TRAIL MODIFY FOR TABLE [Dealer]
if exists(select * from sys.objects where name = 'Dealer' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ModifiedBy' and o.name = 'Dealer')
ALTER TABLE [dbo].[Dealer] ADD [ModifiedBy] [Varchar] (50) NULL
if exists(select * from sys.objects where name = 'Dealer' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ModifiedDate' and o.name = 'Dealer')
ALTER TABLE [dbo].[Dealer] ADD [ModifiedDate] [DateTime] CONSTRAINT [DF__DEALER_MODIFIEDDATE] DEFAULT getdate() NULL

--APPEND AUDIT TRAIL TIMESTAMP FOR TABLE [Dealer]
if exists(select * from sys.objects where name = 'Dealer' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'TimeStamp' and o.name = 'Dealer')
ALTER TABLE [dbo].[Dealer] ADD [TimeStamp] [timestamp] NOT NULL

GO

--APPEND AUDIT TRAIL CREATE FOR TABLE [Feature]
if exists(select * from sys.objects where name = 'Feature' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'CreatedBy' and o.name = 'Feature')
ALTER TABLE [dbo].[Feature] ADD [CreatedBy] [Varchar] (50) NULL
if exists(select * from sys.objects where name = 'Feature' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'CreatedDate' and o.name = 'Feature')
ALTER TABLE [dbo].[Feature] ADD [CreatedDate] [DateTime] CONSTRAINT [DF__FEATURE_CREATEDDATE] DEFAULT getdate() NULL

--APPEND AUDIT TRAIL MODIFY FOR TABLE [Feature]
if exists(select * from sys.objects where name = 'Feature' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ModifiedBy' and o.name = 'Feature')
ALTER TABLE [dbo].[Feature] ADD [ModifiedBy] [Varchar] (50) NULL
if exists(select * from sys.objects where name = 'Feature' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ModifiedDate' and o.name = 'Feature')
ALTER TABLE [dbo].[Feature] ADD [ModifiedDate] [DateTime] CONSTRAINT [DF__FEATURE_MODIFIEDDATE] DEFAULT getdate() NULL

--APPEND AUDIT TRAIL TIMESTAMP FOR TABLE [Feature]
if exists(select * from sys.objects where name = 'Feature' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'TimeStamp' and o.name = 'Feature')
ALTER TABLE [dbo].[Feature] ADD [TimeStamp] [timestamp] NOT NULL

GO

--APPEND AUDIT TRAIL CREATE FOR TABLE [FuelType]
if exists(select * from sys.objects where name = 'FuelType' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'CreatedBy' and o.name = 'FuelType')
ALTER TABLE [dbo].[FuelType] ADD [CreatedBy] [Varchar] (50) NULL
if exists(select * from sys.objects where name = 'FuelType' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'CreatedDate' and o.name = 'FuelType')
ALTER TABLE [dbo].[FuelType] ADD [CreatedDate] [DateTime] CONSTRAINT [DF__FUELTYPE_CREATEDDATE] DEFAULT getdate() NULL

--APPEND AUDIT TRAIL MODIFY FOR TABLE [FuelType]
if exists(select * from sys.objects where name = 'FuelType' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ModifiedBy' and o.name = 'FuelType')
ALTER TABLE [dbo].[FuelType] ADD [ModifiedBy] [Varchar] (50) NULL
if exists(select * from sys.objects where name = 'FuelType' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ModifiedDate' and o.name = 'FuelType')
ALTER TABLE [dbo].[FuelType] ADD [ModifiedDate] [DateTime] CONSTRAINT [DF__FUELTYPE_MODIFIEDDATE] DEFAULT getdate() NULL

--APPEND AUDIT TRAIL TIMESTAMP FOR TABLE [FuelType]
if exists(select * from sys.objects where name = 'FuelType' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'TimeStamp' and o.name = 'FuelType')
ALTER TABLE [dbo].[FuelType] ADD [TimeStamp] [timestamp] NOT NULL

GO

--APPEND AUDIT TRAIL CREATE FOR TABLE [Listing]
if exists(select * from sys.objects where name = 'Listing' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'CreatedBy' and o.name = 'Listing')
ALTER TABLE [dbo].[Listing] ADD [CreatedBy] [Varchar] (50) NULL
if exists(select * from sys.objects where name = 'Listing' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'CreatedDate' and o.name = 'Listing')
ALTER TABLE [dbo].[Listing] ADD [CreatedDate] [DateTime] CONSTRAINT [DF__LISTING_CREATEDDATE] DEFAULT getdate() NULL

--APPEND AUDIT TRAIL MODIFY FOR TABLE [Listing]
if exists(select * from sys.objects where name = 'Listing' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ModifiedBy' and o.name = 'Listing')
ALTER TABLE [dbo].[Listing] ADD [ModifiedBy] [Varchar] (50) NULL
if exists(select * from sys.objects where name = 'Listing' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ModifiedDate' and o.name = 'Listing')
ALTER TABLE [dbo].[Listing] ADD [ModifiedDate] [DateTime] CONSTRAINT [DF__LISTING_MODIFIEDDATE] DEFAULT getdate() NULL

--APPEND AUDIT TRAIL TIMESTAMP FOR TABLE [Listing]
if exists(select * from sys.objects where name = 'Listing' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'TimeStamp' and o.name = 'Listing')
ALTER TABLE [dbo].[Listing] ADD [TimeStamp] [timestamp] NOT NULL

GO

--APPEND AUDIT TRAIL CREATE FOR TABLE [ListingImage]
if exists(select * from sys.objects where name = 'ListingImage' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'CreatedBy' and o.name = 'ListingImage')
ALTER TABLE [dbo].[ListingImage] ADD [CreatedBy] [Varchar] (50) NULL
if exists(select * from sys.objects where name = 'ListingImage' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'CreatedDate' and o.name = 'ListingImage')
ALTER TABLE [dbo].[ListingImage] ADD [CreatedDate] [DateTime] CONSTRAINT [DF__LISTINGIMAGE_CREATEDDATE] DEFAULT getdate() NULL

--APPEND AUDIT TRAIL MODIFY FOR TABLE [ListingImage]
if exists(select * from sys.objects where name = 'ListingImage' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ModifiedBy' and o.name = 'ListingImage')
ALTER TABLE [dbo].[ListingImage] ADD [ModifiedBy] [Varchar] (50) NULL
if exists(select * from sys.objects where name = 'ListingImage' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ModifiedDate' and o.name = 'ListingImage')
ALTER TABLE [dbo].[ListingImage] ADD [ModifiedDate] [DateTime] CONSTRAINT [DF__LISTINGIMAGE_MODIFIEDDATE] DEFAULT getdate() NULL

--APPEND AUDIT TRAIL TIMESTAMP FOR TABLE [ListingImage]
if exists(select * from sys.objects where name = 'ListingImage' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'TimeStamp' and o.name = 'ListingImage')
ALTER TABLE [dbo].[ListingImage] ADD [TimeStamp] [timestamp] NOT NULL

GO

--APPEND AUDIT TRAIL CREATE FOR TABLE [ListingPremium]
if exists(select * from sys.objects where name = 'ListingPremium' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'CreatedBy' and o.name = 'ListingPremium')
ALTER TABLE [dbo].[ListingPremium] ADD [CreatedBy] [Varchar] (50) NULL
if exists(select * from sys.objects where name = 'ListingPremium' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'CreatedDate' and o.name = 'ListingPremium')
ALTER TABLE [dbo].[ListingPremium] ADD [CreatedDate] [DateTime] CONSTRAINT [DF__LISTINGPREMIUM_CREATEDDATE] DEFAULT getdate() NULL

--APPEND AUDIT TRAIL MODIFY FOR TABLE [ListingPremium]
if exists(select * from sys.objects where name = 'ListingPremium' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ModifiedBy' and o.name = 'ListingPremium')
ALTER TABLE [dbo].[ListingPremium] ADD [ModifiedBy] [Varchar] (50) NULL
if exists(select * from sys.objects where name = 'ListingPremium' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ModifiedDate' and o.name = 'ListingPremium')
ALTER TABLE [dbo].[ListingPremium] ADD [ModifiedDate] [DateTime] CONSTRAINT [DF__LISTINGPREMIUM_MODIFIEDDATE] DEFAULT getdate() NULL

--APPEND AUDIT TRAIL TIMESTAMP FOR TABLE [ListingPremium]
if exists(select * from sys.objects where name = 'ListingPremium' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'TimeStamp' and o.name = 'ListingPremium')
ALTER TABLE [dbo].[ListingPremium] ADD [TimeStamp] [timestamp] NOT NULL

GO

--APPEND AUDIT TRAIL CREATE FOR TABLE [ListingSaved]
if exists(select * from sys.objects where name = 'ListingSaved' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'CreatedBy' and o.name = 'ListingSaved')
ALTER TABLE [dbo].[ListingSaved] ADD [CreatedBy] [Varchar] (50) NULL
if exists(select * from sys.objects where name = 'ListingSaved' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'CreatedDate' and o.name = 'ListingSaved')
ALTER TABLE [dbo].[ListingSaved] ADD [CreatedDate] [DateTime] CONSTRAINT [DF__LISTINGSAVED_CREATEDDATE] DEFAULT getdate() NULL

--APPEND AUDIT TRAIL MODIFY FOR TABLE [ListingSaved]
if exists(select * from sys.objects where name = 'ListingSaved' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ModifiedBy' and o.name = 'ListingSaved')
ALTER TABLE [dbo].[ListingSaved] ADD [ModifiedBy] [Varchar] (50) NULL
if exists(select * from sys.objects where name = 'ListingSaved' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ModifiedDate' and o.name = 'ListingSaved')
ALTER TABLE [dbo].[ListingSaved] ADD [ModifiedDate] [DateTime] CONSTRAINT [DF__LISTINGSAVED_MODIFIEDDATE] DEFAULT getdate() NULL

--APPEND AUDIT TRAIL TIMESTAMP FOR TABLE [ListingSaved]
if exists(select * from sys.objects where name = 'ListingSaved' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'TimeStamp' and o.name = 'ListingSaved')
ALTER TABLE [dbo].[ListingSaved] ADD [TimeStamp] [timestamp] NOT NULL

GO

--APPEND AUDIT TRAIL CREATE FOR TABLE [ListingView]
if exists(select * from sys.objects where name = 'ListingView' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'CreatedBy' and o.name = 'ListingView')
ALTER TABLE [dbo].[ListingView] ADD [CreatedBy] [Varchar] (50) NULL
if exists(select * from sys.objects where name = 'ListingView' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'CreatedDate' and o.name = 'ListingView')
ALTER TABLE [dbo].[ListingView] ADD [CreatedDate] [DateTime] CONSTRAINT [DF__LISTINGVIEW_CREATEDDATE] DEFAULT getdate() NULL

GO

--APPEND AUDIT TRAIL CREATE FOR TABLE [Make]
if exists(select * from sys.objects where name = 'Make' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'CreatedBy' and o.name = 'Make')
ALTER TABLE [dbo].[Make] ADD [CreatedBy] [Varchar] (50) NULL
if exists(select * from sys.objects where name = 'Make' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'CreatedDate' and o.name = 'Make')
ALTER TABLE [dbo].[Make] ADD [CreatedDate] [DateTime] CONSTRAINT [DF__MAKE_CREATEDDATE] DEFAULT getdate() NULL

--APPEND AUDIT TRAIL MODIFY FOR TABLE [Make]
if exists(select * from sys.objects where name = 'Make' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ModifiedBy' and o.name = 'Make')
ALTER TABLE [dbo].[Make] ADD [ModifiedBy] [Varchar] (50) NULL
if exists(select * from sys.objects where name = 'Make' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ModifiedDate' and o.name = 'Make')
ALTER TABLE [dbo].[Make] ADD [ModifiedDate] [DateTime] CONSTRAINT [DF__MAKE_MODIFIEDDATE] DEFAULT getdate() NULL

--APPEND AUDIT TRAIL TIMESTAMP FOR TABLE [Make]
if exists(select * from sys.objects where name = 'Make' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'TimeStamp' and o.name = 'Make')
ALTER TABLE [dbo].[Make] ADD [TimeStamp] [timestamp] NOT NULL

GO

--APPEND AUDIT TRAIL CREATE FOR TABLE [MakeModel]
if exists(select * from sys.objects where name = 'MakeModel' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'CreatedBy' and o.name = 'MakeModel')
ALTER TABLE [dbo].[MakeModel] ADD [CreatedBy] [Varchar] (50) NULL
if exists(select * from sys.objects where name = 'MakeModel' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'CreatedDate' and o.name = 'MakeModel')
ALTER TABLE [dbo].[MakeModel] ADD [CreatedDate] [DateTime] CONSTRAINT [DF__MAKEMODEL_CREATEDDATE] DEFAULT getdate() NULL

--APPEND AUDIT TRAIL MODIFY FOR TABLE [MakeModel]
if exists(select * from sys.objects where name = 'MakeModel' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ModifiedBy' and o.name = 'MakeModel')
ALTER TABLE [dbo].[MakeModel] ADD [ModifiedBy] [Varchar] (50) NULL
if exists(select * from sys.objects where name = 'MakeModel' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ModifiedDate' and o.name = 'MakeModel')
ALTER TABLE [dbo].[MakeModel] ADD [ModifiedDate] [DateTime] CONSTRAINT [DF__MAKEMODEL_MODIFIEDDATE] DEFAULT getdate() NULL

--APPEND AUDIT TRAIL TIMESTAMP FOR TABLE [MakeModel]
if exists(select * from sys.objects where name = 'MakeModel' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'TimeStamp' and o.name = 'MakeModel')
ALTER TABLE [dbo].[MakeModel] ADD [TimeStamp] [timestamp] NOT NULL

GO

--APPEND AUDIT TRAIL CREATE FOR TABLE [Metro]
if exists(select * from sys.objects where name = 'Metro' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'CreatedBy' and o.name = 'Metro')
ALTER TABLE [dbo].[Metro] ADD [CreatedBy] [Varchar] (50) NULL
if exists(select * from sys.objects where name = 'Metro' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'CreatedDate' and o.name = 'Metro')
ALTER TABLE [dbo].[Metro] ADD [CreatedDate] [DateTime] CONSTRAINT [DF__METRO_CREATEDDATE] DEFAULT getdate() NULL

--APPEND AUDIT TRAIL MODIFY FOR TABLE [Metro]
if exists(select * from sys.objects where name = 'Metro' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ModifiedBy' and o.name = 'Metro')
ALTER TABLE [dbo].[Metro] ADD [ModifiedBy] [Varchar] (50) NULL
if exists(select * from sys.objects where name = 'Metro' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ModifiedDate' and o.name = 'Metro')
ALTER TABLE [dbo].[Metro] ADD [ModifiedDate] [DateTime] CONSTRAINT [DF__METRO_MODIFIEDDATE] DEFAULT getdate() NULL

--APPEND AUDIT TRAIL TIMESTAMP FOR TABLE [Metro]
if exists(select * from sys.objects where name = 'Metro' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'TimeStamp' and o.name = 'Metro')
ALTER TABLE [dbo].[Metro] ADD [TimeStamp] [timestamp] NOT NULL

GO

--APPEND AUDIT TRAIL CREATE FOR TABLE [Model]
if exists(select * from sys.objects where name = 'Model' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'CreatedBy' and o.name = 'Model')
ALTER TABLE [dbo].[Model] ADD [CreatedBy] [Varchar] (50) NULL
if exists(select * from sys.objects where name = 'Model' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'CreatedDate' and o.name = 'Model')
ALTER TABLE [dbo].[Model] ADD [CreatedDate] [DateTime] CONSTRAINT [DF__MODEL_CREATEDDATE] DEFAULT getdate() NULL

--APPEND AUDIT TRAIL MODIFY FOR TABLE [Model]
if exists(select * from sys.objects where name = 'Model' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ModifiedBy' and o.name = 'Model')
ALTER TABLE [dbo].[Model] ADD [ModifiedBy] [Varchar] (50) NULL
if exists(select * from sys.objects where name = 'Model' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ModifiedDate' and o.name = 'Model')
ALTER TABLE [dbo].[Model] ADD [ModifiedDate] [DateTime] CONSTRAINT [DF__MODEL_MODIFIEDDATE] DEFAULT getdate() NULL

--APPEND AUDIT TRAIL TIMESTAMP FOR TABLE [Model]
if exists(select * from sys.objects where name = 'Model' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'TimeStamp' and o.name = 'Model')
ALTER TABLE [dbo].[Model] ADD [TimeStamp] [timestamp] NOT NULL

GO

--APPEND AUDIT TRAIL CREATE FOR TABLE [SearchSaved]
if exists(select * from sys.objects where name = 'SearchSaved' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'CreatedBy' and o.name = 'SearchSaved')
ALTER TABLE [dbo].[SearchSaved] ADD [CreatedBy] [Varchar] (50) NULL
if exists(select * from sys.objects where name = 'SearchSaved' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'CreatedDate' and o.name = 'SearchSaved')
ALTER TABLE [dbo].[SearchSaved] ADD [CreatedDate] [DateTime] CONSTRAINT [DF__SEARCHSAVED_CREATEDDATE] DEFAULT getdate() NULL

--APPEND AUDIT TRAIL MODIFY FOR TABLE [SearchSaved]
if exists(select * from sys.objects where name = 'SearchSaved' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ModifiedBy' and o.name = 'SearchSaved')
ALTER TABLE [dbo].[SearchSaved] ADD [ModifiedBy] [Varchar] (50) NULL
if exists(select * from sys.objects where name = 'SearchSaved' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ModifiedDate' and o.name = 'SearchSaved')
ALTER TABLE [dbo].[SearchSaved] ADD [ModifiedDate] [DateTime] CONSTRAINT [DF__SEARCHSAVED_MODIFIEDDATE] DEFAULT getdate() NULL

--APPEND AUDIT TRAIL TIMESTAMP FOR TABLE [SearchSaved]
if exists(select * from sys.objects where name = 'SearchSaved' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'TimeStamp' and o.name = 'SearchSaved')
ALTER TABLE [dbo].[SearchSaved] ADD [TimeStamp] [timestamp] NOT NULL

GO

--APPEND AUDIT TRAIL CREATE FOR TABLE [SearchSavedCriteria]
if exists(select * from sys.objects where name = 'SearchSavedCriteria' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'CreatedBy' and o.name = 'SearchSavedCriteria')
ALTER TABLE [dbo].[SearchSavedCriteria] ADD [CreatedBy] [Varchar] (50) NULL
if exists(select * from sys.objects where name = 'SearchSavedCriteria' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'CreatedDate' and o.name = 'SearchSavedCriteria')
ALTER TABLE [dbo].[SearchSavedCriteria] ADD [CreatedDate] [DateTime] CONSTRAINT [DF__SEARCHSAVEDCRITERIA_CREATEDDATE] DEFAULT getdate() NULL

--APPEND AUDIT TRAIL MODIFY FOR TABLE [SearchSavedCriteria]
if exists(select * from sys.objects where name = 'SearchSavedCriteria' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ModifiedBy' and o.name = 'SearchSavedCriteria')
ALTER TABLE [dbo].[SearchSavedCriteria] ADD [ModifiedBy] [Varchar] (50) NULL
if exists(select * from sys.objects where name = 'SearchSavedCriteria' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ModifiedDate' and o.name = 'SearchSavedCriteria')
ALTER TABLE [dbo].[SearchSavedCriteria] ADD [ModifiedDate] [DateTime] CONSTRAINT [DF__SEARCHSAVEDCRITERIA_MODIFIEDDATE] DEFAULT getdate() NULL

--APPEND AUDIT TRAIL TIMESTAMP FOR TABLE [SearchSavedCriteria]
if exists(select * from sys.objects where name = 'SearchSavedCriteria' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'TimeStamp' and o.name = 'SearchSavedCriteria')
ALTER TABLE [dbo].[SearchSavedCriteria] ADD [TimeStamp] [timestamp] NOT NULL

GO

--APPEND AUDIT TRAIL CREATE FOR TABLE [State]
if exists(select * from sys.objects where name = 'State' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'CreatedBy' and o.name = 'State')
ALTER TABLE [dbo].[State] ADD [CreatedBy] [Varchar] (50) NULL
if exists(select * from sys.objects where name = 'State' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'CreatedDate' and o.name = 'State')
ALTER TABLE [dbo].[State] ADD [CreatedDate] [DateTime] CONSTRAINT [DF__STATE_CREATEDDATE] DEFAULT getdate() NULL

--APPEND AUDIT TRAIL MODIFY FOR TABLE [State]
if exists(select * from sys.objects where name = 'State' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ModifiedBy' and o.name = 'State')
ALTER TABLE [dbo].[State] ADD [ModifiedBy] [Varchar] (50) NULL
if exists(select * from sys.objects where name = 'State' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ModifiedDate' and o.name = 'State')
ALTER TABLE [dbo].[State] ADD [ModifiedDate] [DateTime] CONSTRAINT [DF__STATE_MODIFIEDDATE] DEFAULT getdate() NULL

--APPEND AUDIT TRAIL TIMESTAMP FOR TABLE [State]
if exists(select * from sys.objects where name = 'State' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'TimeStamp' and o.name = 'State')
ALTER TABLE [dbo].[State] ADD [TimeStamp] [timestamp] NOT NULL

GO

--APPEND AUDIT TRAIL CREATE FOR TABLE [Transmission]
if exists(select * from sys.objects where name = 'Transmission' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'CreatedBy' and o.name = 'Transmission')
ALTER TABLE [dbo].[Transmission] ADD [CreatedBy] [Varchar] (50) NULL
if exists(select * from sys.objects where name = 'Transmission' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'CreatedDate' and o.name = 'Transmission')
ALTER TABLE [dbo].[Transmission] ADD [CreatedDate] [DateTime] CONSTRAINT [DF__TRANSMISSION_CREATEDDATE] DEFAULT getdate() NULL

--APPEND AUDIT TRAIL MODIFY FOR TABLE [Transmission]
if exists(select * from sys.objects where name = 'Transmission' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ModifiedBy' and o.name = 'Transmission')
ALTER TABLE [dbo].[Transmission] ADD [ModifiedBy] [Varchar] (50) NULL
if exists(select * from sys.objects where name = 'Transmission' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ModifiedDate' and o.name = 'Transmission')
ALTER TABLE [dbo].[Transmission] ADD [ModifiedDate] [DateTime] CONSTRAINT [DF__TRANSMISSION_MODIFIEDDATE] DEFAULT getdate() NULL

--APPEND AUDIT TRAIL TIMESTAMP FOR TABLE [Transmission]
if exists(select * from sys.objects where name = 'Transmission' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'TimeStamp' and o.name = 'Transmission')
ALTER TABLE [dbo].[Transmission] ADD [TimeStamp] [timestamp] NOT NULL

GO

--APPEND AUDIT TRAIL CREATE FOR TABLE [UserAccount]
if exists(select * from sys.objects where name = 'UserAccount' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'CreatedBy' and o.name = 'UserAccount')
ALTER TABLE [dbo].[UserAccount] ADD [CreatedBy] [Varchar] (50) NULL
if exists(select * from sys.objects where name = 'UserAccount' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'CreatedDate' and o.name = 'UserAccount')
ALTER TABLE [dbo].[UserAccount] ADD [CreatedDate] [DateTime] CONSTRAINT [DF__USERACCOUNT_CREATEDDATE] DEFAULT getdate() NULL

--APPEND AUDIT TRAIL MODIFY FOR TABLE [UserAccount]
if exists(select * from sys.objects where name = 'UserAccount' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ModifiedBy' and o.name = 'UserAccount')
ALTER TABLE [dbo].[UserAccount] ADD [ModifiedBy] [Varchar] (50) NULL
if exists(select * from sys.objects where name = 'UserAccount' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ModifiedDate' and o.name = 'UserAccount')
ALTER TABLE [dbo].[UserAccount] ADD [ModifiedDate] [DateTime] CONSTRAINT [DF__USERACCOUNT_MODIFIEDDATE] DEFAULT getdate() NULL

--APPEND AUDIT TRAIL TIMESTAMP FOR TABLE [UserAccount]
if exists(select * from sys.objects where name = 'UserAccount' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'TimeStamp' and o.name = 'UserAccount')
ALTER TABLE [dbo].[UserAccount] ADD [TimeStamp] [timestamp] NOT NULL

GO

--APPEND AUDIT TRAIL CREATE FOR TABLE [UserLoginHistory]
if exists(select * from sys.objects where name = 'UserLoginHistory' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'CreatedBy' and o.name = 'UserLoginHistory')
ALTER TABLE [dbo].[UserLoginHistory] ADD [CreatedBy] [Varchar] (50) NULL
if exists(select * from sys.objects where name = 'UserLoginHistory' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'CreatedDate' and o.name = 'UserLoginHistory')
ALTER TABLE [dbo].[UserLoginHistory] ADD [CreatedDate] [DateTime] CONSTRAINT [DF__USERLOGINHISTORY_CREATEDDATE] DEFAULT getdate() NULL

GO

--APPEND AUDIT TRAIL CREATE FOR TABLE [UserType]
if exists(select * from sys.objects where name = 'UserType' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'CreatedBy' and o.name = 'UserType')
ALTER TABLE [dbo].[UserType] ADD [CreatedBy] [Varchar] (50) NULL
if exists(select * from sys.objects where name = 'UserType' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'CreatedDate' and o.name = 'UserType')
ALTER TABLE [dbo].[UserType] ADD [CreatedDate] [DateTime] CONSTRAINT [DF__USERTYPE_CREATEDDATE] DEFAULT getdate() NULL

--APPEND AUDIT TRAIL MODIFY FOR TABLE [UserType]
if exists(select * from sys.objects where name = 'UserType' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ModifiedBy' and o.name = 'UserType')
ALTER TABLE [dbo].[UserType] ADD [ModifiedBy] [Varchar] (50) NULL
if exists(select * from sys.objects where name = 'UserType' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ModifiedDate' and o.name = 'UserType')
ALTER TABLE [dbo].[UserType] ADD [ModifiedDate] [DateTime] CONSTRAINT [DF__USERTYPE_MODIFIEDDATE] DEFAULT getdate() NULL

--APPEND AUDIT TRAIL TIMESTAMP FOR TABLE [UserType]
if exists(select * from sys.objects where name = 'UserType' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'TimeStamp' and o.name = 'UserType')
ALTER TABLE [dbo].[UserType] ADD [TimeStamp] [timestamp] NOT NULL

GO

--APPEND AUDIT TRAIL CREATE FOR TABLE [VistorContact]
if exists(select * from sys.objects where name = 'VistorContact' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'CreatedBy' and o.name = 'VistorContact')
ALTER TABLE [dbo].[VistorContact] ADD [CreatedBy] [Varchar] (50) NULL
if exists(select * from sys.objects where name = 'VistorContact' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'CreatedDate' and o.name = 'VistorContact')
ALTER TABLE [dbo].[VistorContact] ADD [CreatedDate] [DateTime] CONSTRAINT [DF__VISTORCONTACT_CREATEDDATE] DEFAULT getdate() NULL

--APPEND AUDIT TRAIL MODIFY FOR TABLE [VistorContact]
if exists(select * from sys.objects where name = 'VistorContact' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ModifiedBy' and o.name = 'VistorContact')
ALTER TABLE [dbo].[VistorContact] ADD [ModifiedBy] [Varchar] (50) NULL
if exists(select * from sys.objects where name = 'VistorContact' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ModifiedDate' and o.name = 'VistorContact')
ALTER TABLE [dbo].[VistorContact] ADD [ModifiedDate] [DateTime] CONSTRAINT [DF__VISTORCONTACT_MODIFIEDDATE] DEFAULT getdate() NULL

--APPEND AUDIT TRAIL TIMESTAMP FOR TABLE [VistorContact]
if exists(select * from sys.objects where name = 'VistorContact' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'TimeStamp' and o.name = 'VistorContact')
ALTER TABLE [dbo].[VistorContact] ADD [TimeStamp] [timestamp] NOT NULL

GO

--APPEND AUDIT TRAIL CREATE FOR TABLE [Zip]
if exists(select * from sys.objects where name = 'Zip' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'CreatedBy' and o.name = 'Zip')
ALTER TABLE [dbo].[Zip] ADD [CreatedBy] [Varchar] (50) NULL
if exists(select * from sys.objects where name = 'Zip' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'CreatedDate' and o.name = 'Zip')
ALTER TABLE [dbo].[Zip] ADD [CreatedDate] [DateTime] CONSTRAINT [DF__ZIP_CREATEDDATE] DEFAULT getdate() NULL

--APPEND AUDIT TRAIL MODIFY FOR TABLE [Zip]
if exists(select * from sys.objects where name = 'Zip' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ModifiedBy' and o.name = 'Zip')
ALTER TABLE [dbo].[Zip] ADD [ModifiedBy] [Varchar] (50) NULL
if exists(select * from sys.objects where name = 'Zip' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ModifiedDate' and o.name = 'Zip')
ALTER TABLE [dbo].[Zip] ADD [ModifiedDate] [DateTime] CONSTRAINT [DF__ZIP_MODIFIEDDATE] DEFAULT getdate() NULL

--APPEND AUDIT TRAIL TIMESTAMP FOR TABLE [Zip]
if exists(select * from sys.objects where name = 'Zip' and type = 'U') and not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'TimeStamp' and o.name = 'Zip')
ALTER TABLE [dbo].[Zip] ADD [TimeStamp] [timestamp] NOT NULL

GO

--##SECTION END [AUDIT TRAIL CREATE]

--##SECTION BEGIN [AUDIT TRAIL REMOVE]

--REMOVE AUDIT TRAIL CREATE FOR TABLE [CityZip]
if exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'CreatedBy' and o.name = 'CityZip')
ALTER TABLE [dbo].[CityZip] DROP COLUMN [CreatedBy]
if exists (select * from sys.objects where name = 'DF__CITYZIP_CREATEDDATE' and [type] = 'D')
ALTER TABLE [dbo].[CityZip] DROP CONSTRAINT [DF__CITYZIP_CREATEDDATE]
if exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'CreatedDate' and o.name = 'CityZip')
ALTER TABLE [dbo].[CityZip] DROP COLUMN [CreatedDate]

--REMOVE AUDIT TRAIL MODIFY FOR TABLE [CityZip]
if exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ModifiedBy' and o.name = 'CityZip')
ALTER TABLE [dbo].[CityZip] DROP COLUMN [ModifiedBy]
if exists (select * from sys.objects where name = 'DF__CITYZIP_MODIFIEDDATE' and [type] = 'D')
ALTER TABLE [dbo].[CityZip] DROP CONSTRAINT [DF__CITYZIP_MODIFIEDDATE]
if exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ModifiedDate' and o.name = 'CityZip')
ALTER TABLE [dbo].[CityZip] DROP COLUMN [ModifiedDate]

--REMOVE AUDIT TRAIL TIMESTAMP FOR TABLE [CityZip]
if exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'TimeStamp' and o.name = 'CityZip')
ALTER TABLE [dbo].[CityZip] DROP COLUMN [TimeStamp]

GO

--REMOVE AUDIT TRAIL CREATE FOR TABLE [ListingFeature]
if exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'CreatedBy' and o.name = 'ListingFeature')
ALTER TABLE [dbo].[ListingFeature] DROP COLUMN [CreatedBy]
if exists (select * from sys.objects where name = 'DF__LISTINGFEATURE_CREATEDDATE' and [type] = 'D')
ALTER TABLE [dbo].[ListingFeature] DROP CONSTRAINT [DF__LISTINGFEATURE_CREATEDDATE]
if exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'CreatedDate' and o.name = 'ListingFeature')
ALTER TABLE [dbo].[ListingFeature] DROP COLUMN [CreatedDate]

--REMOVE AUDIT TRAIL MODIFY FOR TABLE [ListingFeature]
if exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ModifiedBy' and o.name = 'ListingFeature')
ALTER TABLE [dbo].[ListingFeature] DROP COLUMN [ModifiedBy]
if exists (select * from sys.objects where name = 'DF__LISTINGFEATURE_MODIFIEDDATE' and [type] = 'D')
ALTER TABLE [dbo].[ListingFeature] DROP CONSTRAINT [DF__LISTINGFEATURE_MODIFIEDDATE]
if exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ModifiedDate' and o.name = 'ListingFeature')
ALTER TABLE [dbo].[ListingFeature] DROP COLUMN [ModifiedDate]

--REMOVE AUDIT TRAIL TIMESTAMP FOR TABLE [ListingFeature]
if exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'TimeStamp' and o.name = 'ListingFeature')
ALTER TABLE [dbo].[ListingFeature] DROP COLUMN [TimeStamp]

GO

--REMOVE AUDIT TRAIL MODIFY FOR TABLE [ListingView]
if exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ModifiedBy' and o.name = 'ListingView')
ALTER TABLE [dbo].[ListingView] DROP COLUMN [ModifiedBy]
if exists (select * from sys.objects where name = 'DF__LISTINGVIEW_MODIFIEDDATE' and [type] = 'D')
ALTER TABLE [dbo].[ListingView] DROP CONSTRAINT [DF__LISTINGVIEW_MODIFIEDDATE]
if exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ModifiedDate' and o.name = 'ListingView')
ALTER TABLE [dbo].[ListingView] DROP COLUMN [ModifiedDate]

--REMOVE AUDIT TRAIL TIMESTAMP FOR TABLE [ListingView]
if exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'TimeStamp' and o.name = 'ListingView')
ALTER TABLE [dbo].[ListingView] DROP COLUMN [TimeStamp]

GO

--REMOVE AUDIT TRAIL CREATE FOR TABLE [MetroState]
if exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'CreatedBy' and o.name = 'MetroState')
ALTER TABLE [dbo].[MetroState] DROP COLUMN [CreatedBy]
if exists (select * from sys.objects where name = 'DF__METROSTATE_CREATEDDATE' and [type] = 'D')
ALTER TABLE [dbo].[MetroState] DROP CONSTRAINT [DF__METROSTATE_CREATEDDATE]
if exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'CreatedDate' and o.name = 'MetroState')
ALTER TABLE [dbo].[MetroState] DROP COLUMN [CreatedDate]

--REMOVE AUDIT TRAIL MODIFY FOR TABLE [MetroState]
if exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ModifiedBy' and o.name = 'MetroState')
ALTER TABLE [dbo].[MetroState] DROP COLUMN [ModifiedBy]
if exists (select * from sys.objects where name = 'DF__METROSTATE_MODIFIEDDATE' and [type] = 'D')
ALTER TABLE [dbo].[MetroState] DROP CONSTRAINT [DF__METROSTATE_MODIFIEDDATE]
if exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ModifiedDate' and o.name = 'MetroState')
ALTER TABLE [dbo].[MetroState] DROP COLUMN [ModifiedDate]

--REMOVE AUDIT TRAIL TIMESTAMP FOR TABLE [MetroState]
if exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'TimeStamp' and o.name = 'MetroState')
ALTER TABLE [dbo].[MetroState] DROP COLUMN [TimeStamp]

GO

--REMOVE AUDIT TRAIL CREATE FOR TABLE [MetroZip]
if exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'CreatedBy' and o.name = 'MetroZip')
ALTER TABLE [dbo].[MetroZip] DROP COLUMN [CreatedBy]
if exists (select * from sys.objects where name = 'DF__METROZIP_CREATEDDATE' and [type] = 'D')
ALTER TABLE [dbo].[MetroZip] DROP CONSTRAINT [DF__METROZIP_CREATEDDATE]
if exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'CreatedDate' and o.name = 'MetroZip')
ALTER TABLE [dbo].[MetroZip] DROP COLUMN [CreatedDate]

--REMOVE AUDIT TRAIL MODIFY FOR TABLE [MetroZip]
if exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ModifiedBy' and o.name = 'MetroZip')
ALTER TABLE [dbo].[MetroZip] DROP COLUMN [ModifiedBy]
if exists (select * from sys.objects where name = 'DF__METROZIP_MODIFIEDDATE' and [type] = 'D')
ALTER TABLE [dbo].[MetroZip] DROP CONSTRAINT [DF__METROZIP_MODIFIEDDATE]
if exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ModifiedDate' and o.name = 'MetroZip')
ALTER TABLE [dbo].[MetroZip] DROP COLUMN [ModifiedDate]

--REMOVE AUDIT TRAIL TIMESTAMP FOR TABLE [MetroZip]
if exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'TimeStamp' and o.name = 'MetroZip')
ALTER TABLE [dbo].[MetroZip] DROP COLUMN [TimeStamp]

GO

--REMOVE AUDIT TRAIL MODIFY FOR TABLE [UserLoginHistory]
if exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ModifiedBy' and o.name = 'UserLoginHistory')
ALTER TABLE [dbo].[UserLoginHistory] DROP COLUMN [ModifiedBy]
if exists (select * from sys.objects where name = 'DF__USERLOGINHISTORY_MODIFIEDDATE' and [type] = 'D')
ALTER TABLE [dbo].[UserLoginHistory] DROP CONSTRAINT [DF__USERLOGINHISTORY_MODIFIEDDATE]
if exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'ModifiedDate' and o.name = 'UserLoginHistory')
ALTER TABLE [dbo].[UserLoginHistory] DROP COLUMN [ModifiedDate]

--REMOVE AUDIT TRAIL TIMESTAMP FOR TABLE [UserLoginHistory]
if exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'TimeStamp' and o.name = 'UserLoginHistory')
ALTER TABLE [dbo].[UserLoginHistory] DROP COLUMN [TimeStamp]

GO

--##SECTION END [AUDIT TRAIL REMOVE]

--##SECTION BEGIN [RENAME PK]

--RENAME EXISTING PRIMARY KEYS IF NECESSARY
DECLARE @pkfixAdministrator varchar(500)
SET @pkfixAdministrator = (SELECT top 1 i.name AS IndexName FROM sys.indexes AS i WHERE i.is_primary_key = 1 AND OBJECT_NAME(i.OBJECT_ID) = 'Administrator')
if @pkfixAdministrator <> '' and (BINARY_CHECKSUM(@pkfixAdministrator) <> BINARY_CHECKSUM('PK_ADMINISTRATOR')) exec('sp_rename '''+@pkfixAdministrator+''', ''PK_ADMINISTRATOR''')
DECLARE @pkfixBodyType varchar(500)
SET @pkfixBodyType = (SELECT top 1 i.name AS IndexName FROM sys.indexes AS i WHERE i.is_primary_key = 1 AND OBJECT_NAME(i.OBJECT_ID) = 'BodyType')
if @pkfixBodyType <> '' and (BINARY_CHECKSUM(@pkfixBodyType) <> BINARY_CHECKSUM('PK_BODYTYPE')) exec('sp_rename '''+@pkfixBodyType+''', ''PK_BODYTYPE''')
DECLARE @pkfixBulletPoint varchar(500)
SET @pkfixBulletPoint = (SELECT top 1 i.name AS IndexName FROM sys.indexes AS i WHERE i.is_primary_key = 1 AND OBJECT_NAME(i.OBJECT_ID) = 'BulletPoint')
if @pkfixBulletPoint <> '' and (BINARY_CHECKSUM(@pkfixBulletPoint) <> BINARY_CHECKSUM('PK_BULLETPOINT')) exec('sp_rename '''+@pkfixBulletPoint+''', ''PK_BULLETPOINT''')
DECLARE @pkfixCity varchar(500)
SET @pkfixCity = (SELECT top 1 i.name AS IndexName FROM sys.indexes AS i WHERE i.is_primary_key = 1 AND OBJECT_NAME(i.OBJECT_ID) = 'City')
if @pkfixCity <> '' and (BINARY_CHECKSUM(@pkfixCity) <> BINARY_CHECKSUM('PK_CITY')) exec('sp_rename '''+@pkfixCity+''', ''PK_CITY''')
DECLARE @pkfixCityZip varchar(500)
SET @pkfixCityZip = (SELECT top 1 i.name AS IndexName FROM sys.indexes AS i WHERE i.is_primary_key = 1 AND OBJECT_NAME(i.OBJECT_ID) = 'CityZip')
if @pkfixCityZip <> '' and (BINARY_CHECKSUM(@pkfixCityZip) <> BINARY_CHECKSUM('PK_CITYZIP')) exec('sp_rename '''+@pkfixCityZip+''', ''PK_CITYZIP''')
DECLARE @pkfixColor varchar(500)
SET @pkfixColor = (SELECT top 1 i.name AS IndexName FROM sys.indexes AS i WHERE i.is_primary_key = 1 AND OBJECT_NAME(i.OBJECT_ID) = 'Color')
if @pkfixColor <> '' and (BINARY_CHECKSUM(@pkfixColor) <> BINARY_CHECKSUM('PK_COLOR')) exec('sp_rename '''+@pkfixColor+''', ''PK_COLOR''')
DECLARE @pkfixCondition varchar(500)
SET @pkfixCondition = (SELECT top 1 i.name AS IndexName FROM sys.indexes AS i WHERE i.is_primary_key = 1 AND OBJECT_NAME(i.OBJECT_ID) = 'Condition')
if @pkfixCondition <> '' and (BINARY_CHECKSUM(@pkfixCondition) <> BINARY_CHECKSUM('PK_CONDITION')) exec('sp_rename '''+@pkfixCondition+''', ''PK_CONDITION''')
DECLARE @pkfixConfigSetting varchar(500)
SET @pkfixConfigSetting = (SELECT top 1 i.name AS IndexName FROM sys.indexes AS i WHERE i.is_primary_key = 1 AND OBJECT_NAME(i.OBJECT_ID) = 'ConfigSetting')
if @pkfixConfigSetting <> '' and (BINARY_CHECKSUM(@pkfixConfigSetting) <> BINARY_CHECKSUM('PK_CONFIGSETTING')) exec('sp_rename '''+@pkfixConfigSetting+''', ''PK_CONFIGSETTING''')
DECLARE @pkfixDealer varchar(500)
SET @pkfixDealer = (SELECT top 1 i.name AS IndexName FROM sys.indexes AS i WHERE i.is_primary_key = 1 AND OBJECT_NAME(i.OBJECT_ID) = 'Dealer')
if @pkfixDealer <> '' and (BINARY_CHECKSUM(@pkfixDealer) <> BINARY_CHECKSUM('PK_DEALER')) exec('sp_rename '''+@pkfixDealer+''', ''PK_DEALER''')
DECLARE @pkfixFeature varchar(500)
SET @pkfixFeature = (SELECT top 1 i.name AS IndexName FROM sys.indexes AS i WHERE i.is_primary_key = 1 AND OBJECT_NAME(i.OBJECT_ID) = 'Feature')
if @pkfixFeature <> '' and (BINARY_CHECKSUM(@pkfixFeature) <> BINARY_CHECKSUM('PK_FEATURE')) exec('sp_rename '''+@pkfixFeature+''', ''PK_FEATURE''')
DECLARE @pkfixFuelType varchar(500)
SET @pkfixFuelType = (SELECT top 1 i.name AS IndexName FROM sys.indexes AS i WHERE i.is_primary_key = 1 AND OBJECT_NAME(i.OBJECT_ID) = 'FuelType')
if @pkfixFuelType <> '' and (BINARY_CHECKSUM(@pkfixFuelType) <> BINARY_CHECKSUM('PK_FUELTYPE')) exec('sp_rename '''+@pkfixFuelType+''', ''PK_FUELTYPE''')
DECLARE @pkfixListing varchar(500)
SET @pkfixListing = (SELECT top 1 i.name AS IndexName FROM sys.indexes AS i WHERE i.is_primary_key = 1 AND OBJECT_NAME(i.OBJECT_ID) = 'Listing')
if @pkfixListing <> '' and (BINARY_CHECKSUM(@pkfixListing) <> BINARY_CHECKSUM('PK_LISTING')) exec('sp_rename '''+@pkfixListing+''', ''PK_LISTING''')
DECLARE @pkfixListingFeature varchar(500)
SET @pkfixListingFeature = (SELECT top 1 i.name AS IndexName FROM sys.indexes AS i WHERE i.is_primary_key = 1 AND OBJECT_NAME(i.OBJECT_ID) = 'ListingFeature')
if @pkfixListingFeature <> '' and (BINARY_CHECKSUM(@pkfixListingFeature) <> BINARY_CHECKSUM('PK_LISTINGFEATURE')) exec('sp_rename '''+@pkfixListingFeature+''', ''PK_LISTINGFEATURE''')
DECLARE @pkfixListingImage varchar(500)
SET @pkfixListingImage = (SELECT top 1 i.name AS IndexName FROM sys.indexes AS i WHERE i.is_primary_key = 1 AND OBJECT_NAME(i.OBJECT_ID) = 'ListingImage')
if @pkfixListingImage <> '' and (BINARY_CHECKSUM(@pkfixListingImage) <> BINARY_CHECKSUM('PK_LISTINGIMAGE')) exec('sp_rename '''+@pkfixListingImage+''', ''PK_LISTINGIMAGE''')
DECLARE @pkfixListingPremium varchar(500)
SET @pkfixListingPremium = (SELECT top 1 i.name AS IndexName FROM sys.indexes AS i WHERE i.is_primary_key = 1 AND OBJECT_NAME(i.OBJECT_ID) = 'ListingPremium')
if @pkfixListingPremium <> '' and (BINARY_CHECKSUM(@pkfixListingPremium) <> BINARY_CHECKSUM('PK_LISTINGPREMIUM')) exec('sp_rename '''+@pkfixListingPremium+''', ''PK_LISTINGPREMIUM''')
DECLARE @pkfixListingSaved varchar(500)
SET @pkfixListingSaved = (SELECT top 1 i.name AS IndexName FROM sys.indexes AS i WHERE i.is_primary_key = 1 AND OBJECT_NAME(i.OBJECT_ID) = 'ListingSaved')
if @pkfixListingSaved <> '' and (BINARY_CHECKSUM(@pkfixListingSaved) <> BINARY_CHECKSUM('PK_LISTINGSAVED')) exec('sp_rename '''+@pkfixListingSaved+''', ''PK_LISTINGSAVED''')
DECLARE @pkfixListingView varchar(500)
SET @pkfixListingView = (SELECT top 1 i.name AS IndexName FROM sys.indexes AS i WHERE i.is_primary_key = 1 AND OBJECT_NAME(i.OBJECT_ID) = 'ListingView')
if @pkfixListingView <> '' and (BINARY_CHECKSUM(@pkfixListingView) <> BINARY_CHECKSUM('PK_LISTINGVIEW')) exec('sp_rename '''+@pkfixListingView+''', ''PK_LISTINGVIEW''')
DECLARE @pkfixMake varchar(500)
SET @pkfixMake = (SELECT top 1 i.name AS IndexName FROM sys.indexes AS i WHERE i.is_primary_key = 1 AND OBJECT_NAME(i.OBJECT_ID) = 'Make')
if @pkfixMake <> '' and (BINARY_CHECKSUM(@pkfixMake) <> BINARY_CHECKSUM('PK_MAKE')) exec('sp_rename '''+@pkfixMake+''', ''PK_MAKE''')
DECLARE @pkfixMakeModel varchar(500)
SET @pkfixMakeModel = (SELECT top 1 i.name AS IndexName FROM sys.indexes AS i WHERE i.is_primary_key = 1 AND OBJECT_NAME(i.OBJECT_ID) = 'MakeModel')
if @pkfixMakeModel <> '' and (BINARY_CHECKSUM(@pkfixMakeModel) <> BINARY_CHECKSUM('PK_MAKEMODEL')) exec('sp_rename '''+@pkfixMakeModel+''', ''PK_MAKEMODEL''')
DECLARE @pkfixMetro varchar(500)
SET @pkfixMetro = (SELECT top 1 i.name AS IndexName FROM sys.indexes AS i WHERE i.is_primary_key = 1 AND OBJECT_NAME(i.OBJECT_ID) = 'Metro')
if @pkfixMetro <> '' and (BINARY_CHECKSUM(@pkfixMetro) <> BINARY_CHECKSUM('PK_METRO')) exec('sp_rename '''+@pkfixMetro+''', ''PK_METRO''')
DECLARE @pkfixMetroState varchar(500)
SET @pkfixMetroState = (SELECT top 1 i.name AS IndexName FROM sys.indexes AS i WHERE i.is_primary_key = 1 AND OBJECT_NAME(i.OBJECT_ID) = 'MetroState')
if @pkfixMetroState <> '' and (BINARY_CHECKSUM(@pkfixMetroState) <> BINARY_CHECKSUM('PK_METROSTATE')) exec('sp_rename '''+@pkfixMetroState+''', ''PK_METROSTATE''')
DECLARE @pkfixMetroZip varchar(500)
SET @pkfixMetroZip = (SELECT top 1 i.name AS IndexName FROM sys.indexes AS i WHERE i.is_primary_key = 1 AND OBJECT_NAME(i.OBJECT_ID) = 'MetroZip')
if @pkfixMetroZip <> '' and (BINARY_CHECKSUM(@pkfixMetroZip) <> BINARY_CHECKSUM('PK_METROZIP')) exec('sp_rename '''+@pkfixMetroZip+''', ''PK_METROZIP''')
DECLARE @pkfixModel varchar(500)
SET @pkfixModel = (SELECT top 1 i.name AS IndexName FROM sys.indexes AS i WHERE i.is_primary_key = 1 AND OBJECT_NAME(i.OBJECT_ID) = 'Model')
if @pkfixModel <> '' and (BINARY_CHECKSUM(@pkfixModel) <> BINARY_CHECKSUM('PK_MODEL')) exec('sp_rename '''+@pkfixModel+''', ''PK_MODEL''')
DECLARE @pkfixSearchSaved varchar(500)
SET @pkfixSearchSaved = (SELECT top 1 i.name AS IndexName FROM sys.indexes AS i WHERE i.is_primary_key = 1 AND OBJECT_NAME(i.OBJECT_ID) = 'SearchSaved')
if @pkfixSearchSaved <> '' and (BINARY_CHECKSUM(@pkfixSearchSaved) <> BINARY_CHECKSUM('PK_SEARCHSAVED')) exec('sp_rename '''+@pkfixSearchSaved+''', ''PK_SEARCHSAVED''')
DECLARE @pkfixSearchSavedCriteria varchar(500)
SET @pkfixSearchSavedCriteria = (SELECT top 1 i.name AS IndexName FROM sys.indexes AS i WHERE i.is_primary_key = 1 AND OBJECT_NAME(i.OBJECT_ID) = 'SearchSavedCriteria')
if @pkfixSearchSavedCriteria <> '' and (BINARY_CHECKSUM(@pkfixSearchSavedCriteria) <> BINARY_CHECKSUM('PK_SEARCHSAVEDCRITERIA')) exec('sp_rename '''+@pkfixSearchSavedCriteria+''', ''PK_SEARCHSAVEDCRITERIA''')
DECLARE @pkfixState varchar(500)
SET @pkfixState = (SELECT top 1 i.name AS IndexName FROM sys.indexes AS i WHERE i.is_primary_key = 1 AND OBJECT_NAME(i.OBJECT_ID) = 'State')
if @pkfixState <> '' and (BINARY_CHECKSUM(@pkfixState) <> BINARY_CHECKSUM('PK_STATE')) exec('sp_rename '''+@pkfixState+''', ''PK_STATE''')
DECLARE @pkfixTransmission varchar(500)
SET @pkfixTransmission = (SELECT top 1 i.name AS IndexName FROM sys.indexes AS i WHERE i.is_primary_key = 1 AND OBJECT_NAME(i.OBJECT_ID) = 'Transmission')
if @pkfixTransmission <> '' and (BINARY_CHECKSUM(@pkfixTransmission) <> BINARY_CHECKSUM('PK_TRANSMISSION')) exec('sp_rename '''+@pkfixTransmission+''', ''PK_TRANSMISSION''')
DECLARE @pkfixUserAccount varchar(500)
SET @pkfixUserAccount = (SELECT top 1 i.name AS IndexName FROM sys.indexes AS i WHERE i.is_primary_key = 1 AND OBJECT_NAME(i.OBJECT_ID) = 'UserAccount')
if @pkfixUserAccount <> '' and (BINARY_CHECKSUM(@pkfixUserAccount) <> BINARY_CHECKSUM('PK_USERACCOUNT')) exec('sp_rename '''+@pkfixUserAccount+''', ''PK_USERACCOUNT''')
DECLARE @pkfixUserLoginHistory varchar(500)
SET @pkfixUserLoginHistory = (SELECT top 1 i.name AS IndexName FROM sys.indexes AS i WHERE i.is_primary_key = 1 AND OBJECT_NAME(i.OBJECT_ID) = 'UserLoginHistory')
if @pkfixUserLoginHistory <> '' and (BINARY_CHECKSUM(@pkfixUserLoginHistory) <> BINARY_CHECKSUM('PK_USERLOGINHISTORY')) exec('sp_rename '''+@pkfixUserLoginHistory+''', ''PK_USERLOGINHISTORY''')
DECLARE @pkfixUserType varchar(500)
SET @pkfixUserType = (SELECT top 1 i.name AS IndexName FROM sys.indexes AS i WHERE i.is_primary_key = 1 AND OBJECT_NAME(i.OBJECT_ID) = 'UserType')
if @pkfixUserType <> '' and (BINARY_CHECKSUM(@pkfixUserType) <> BINARY_CHECKSUM('PK_USERTYPE')) exec('sp_rename '''+@pkfixUserType+''', ''PK_USERTYPE''')
DECLARE @pkfixVistorContact varchar(500)
SET @pkfixVistorContact = (SELECT top 1 i.name AS IndexName FROM sys.indexes AS i WHERE i.is_primary_key = 1 AND OBJECT_NAME(i.OBJECT_ID) = 'VistorContact')
if @pkfixVistorContact <> '' and (BINARY_CHECKSUM(@pkfixVistorContact) <> BINARY_CHECKSUM('PK_VISTORCONTACT')) exec('sp_rename '''+@pkfixVistorContact+''', ''PK_VISTORCONTACT''')
DECLARE @pkfixZip varchar(500)
SET @pkfixZip = (SELECT top 1 i.name AS IndexName FROM sys.indexes AS i WHERE i.is_primary_key = 1 AND OBJECT_NAME(i.OBJECT_ID) = 'Zip')
if @pkfixZip <> '' and (BINARY_CHECKSUM(@pkfixZip) <> BINARY_CHECKSUM('PK_ZIP')) exec('sp_rename '''+@pkfixZip+''', ''PK_ZIP''')
GO

--##SECTION END [RENAME PK]

--##SECTION BEGIN [DROP PK]

--##SECTION END [DROP PK]

--##SECTION BEGIN [CREATE PK]

--PRIMARY KEY FOR TABLE [Administrator]
if not exists(select * from sysobjects where name = 'PK_ADMINISTRATOR' and xtype = 'PK')
ALTER TABLE [dbo].[Administrator] WITH NOCHECK ADD 
CONSTRAINT [PK_ADMINISTRATOR] PRIMARY KEY CLUSTERED
(
	[AdministratorId]
)
GO
--PRIMARY KEY FOR TABLE [BodyType]
if not exists(select * from sysobjects where name = 'PK_BODYTYPE' and xtype = 'PK')
ALTER TABLE [dbo].[BodyType] WITH NOCHECK ADD 
CONSTRAINT [PK_BODYTYPE] PRIMARY KEY CLUSTERED
(
	[BodyTypeId]
)
GO
--PRIMARY KEY FOR TABLE [BulletPoint]
if not exists(select * from sysobjects where name = 'PK_BULLETPOINT' and xtype = 'PK')
ALTER TABLE [dbo].[BulletPoint] WITH NOCHECK ADD 
CONSTRAINT [PK_BULLETPOINT] PRIMARY KEY CLUSTERED
(
	[BulletPointId]
)
GO
--PRIMARY KEY FOR TABLE [City]
if not exists(select * from sysobjects where name = 'PK_CITY' and xtype = 'PK')
ALTER TABLE [dbo].[City] WITH NOCHECK ADD 
CONSTRAINT [PK_CITY] PRIMARY KEY CLUSTERED
(
	[CityId]
)
GO
--PRIMARY KEY FOR TABLE [CityZip]
if not exists(select * from sysobjects where name = 'PK_CITYZIP' and xtype = 'PK')
ALTER TABLE [dbo].[CityZip] WITH NOCHECK ADD 
CONSTRAINT [PK_CITYZIP] PRIMARY KEY CLUSTERED
(
	[CityId],
	[ZipId]
)
GO
--PRIMARY KEY FOR TABLE [Color]
if not exists(select * from sysobjects where name = 'PK_COLOR' and xtype = 'PK')
ALTER TABLE [dbo].[Color] WITH NOCHECK ADD 
CONSTRAINT [PK_COLOR] PRIMARY KEY CLUSTERED
(
	[ColorId]
)
GO
--PRIMARY KEY FOR TABLE [Condition]
if not exists(select * from sysobjects where name = 'PK_CONDITION' and xtype = 'PK')
ALTER TABLE [dbo].[Condition] WITH NOCHECK ADD 
CONSTRAINT [PK_CONDITION] PRIMARY KEY CLUSTERED
(
	[ConditionId]
)
GO
--PRIMARY KEY FOR TABLE [ConfigSetting]
if not exists(select * from sysobjects where name = 'PK_CONFIGSETTING' and xtype = 'PK')
ALTER TABLE [dbo].[ConfigSetting] WITH NOCHECK ADD 
CONSTRAINT [PK_CONFIGSETTING] PRIMARY KEY CLUSTERED
(
	[ID]
)
GO
--PRIMARY KEY FOR TABLE [Dealer]
if not exists(select * from sysobjects where name = 'PK_DEALER' and xtype = 'PK')
ALTER TABLE [dbo].[Dealer] WITH NOCHECK ADD 
CONSTRAINT [PK_DEALER] PRIMARY KEY CLUSTERED
(
	[UserId]
)
GO
--PRIMARY KEY FOR TABLE [Feature]
if not exists(select * from sysobjects where name = 'PK_FEATURE' and xtype = 'PK')
ALTER TABLE [dbo].[Feature] WITH NOCHECK ADD 
CONSTRAINT [PK_FEATURE] PRIMARY KEY CLUSTERED
(
	[FeatureId]
)
GO
--PRIMARY KEY FOR TABLE [FuelType]
if not exists(select * from sysobjects where name = 'PK_FUELTYPE' and xtype = 'PK')
ALTER TABLE [dbo].[FuelType] WITH NOCHECK ADD 
CONSTRAINT [PK_FUELTYPE] PRIMARY KEY CLUSTERED
(
	[FuelTypeId]
)
GO
--PRIMARY KEY FOR TABLE [Listing]
if not exists(select * from sysobjects where name = 'PK_LISTING' and xtype = 'PK')
ALTER TABLE [dbo].[Listing] WITH NOCHECK ADD 
CONSTRAINT [PK_LISTING] PRIMARY KEY CLUSTERED
(
	[ListingId]
)
GO
--PRIMARY KEY FOR TABLE [ListingFeature]
if not exists(select * from sysobjects where name = 'PK_LISTINGFEATURE' and xtype = 'PK')
ALTER TABLE [dbo].[ListingFeature] WITH NOCHECK ADD 
CONSTRAINT [PK_LISTINGFEATURE] PRIMARY KEY CLUSTERED
(
	[FeatureId],
	[ListingId]
)
GO
--PRIMARY KEY FOR TABLE [ListingImage]
if not exists(select * from sysobjects where name = 'PK_LISTINGIMAGE' and xtype = 'PK')
ALTER TABLE [dbo].[ListingImage] WITH NOCHECK ADD 
CONSTRAINT [PK_LISTINGIMAGE] PRIMARY KEY CLUSTERED
(
	[ListingImageId]
)
GO
--PRIMARY KEY FOR TABLE [ListingPremium]
if not exists(select * from sysobjects where name = 'PK_LISTINGPREMIUM' and xtype = 'PK')
ALTER TABLE [dbo].[ListingPremium] WITH NOCHECK ADD 
CONSTRAINT [PK_LISTINGPREMIUM] PRIMARY KEY CLUSTERED
(
	[ListingPremiumId]
)
GO
--PRIMARY KEY FOR TABLE [ListingSaved]
if not exists(select * from sysobjects where name = 'PK_LISTINGSAVED' and xtype = 'PK')
ALTER TABLE [dbo].[ListingSaved] WITH NOCHECK ADD 
CONSTRAINT [PK_LISTINGSAVED] PRIMARY KEY CLUSTERED
(
	[ListingId],
	[UserId]
)
GO
--PRIMARY KEY FOR TABLE [ListingView]
if not exists(select * from sysobjects where name = 'PK_LISTINGVIEW' and xtype = 'PK')
ALTER TABLE [dbo].[ListingView] WITH NOCHECK ADD 
CONSTRAINT [PK_LISTINGVIEW] PRIMARY KEY CLUSTERED
(
	[ListingViewId]
)
GO
--PRIMARY KEY FOR TABLE [Make]
if not exists(select * from sysobjects where name = 'PK_MAKE' and xtype = 'PK')
ALTER TABLE [dbo].[Make] WITH NOCHECK ADD 
CONSTRAINT [PK_MAKE] PRIMARY KEY CLUSTERED
(
	[MakeId]
)
GO
--PRIMARY KEY FOR TABLE [MakeModel]
if not exists(select * from sysobjects where name = 'PK_MAKEMODEL' and xtype = 'PK')
ALTER TABLE [dbo].[MakeModel] WITH NOCHECK ADD 
CONSTRAINT [PK_MAKEMODEL] PRIMARY KEY CLUSTERED
(
	[MakeModelId]
)
GO
--PRIMARY KEY FOR TABLE [Metro]
if not exists(select * from sysobjects where name = 'PK_METRO' and xtype = 'PK')
ALTER TABLE [dbo].[Metro] WITH NOCHECK ADD 
CONSTRAINT [PK_METRO] PRIMARY KEY CLUSTERED
(
	[MetroId]
)
GO
--PRIMARY KEY FOR TABLE [MetroState]
if not exists(select * from sysobjects where name = 'PK_METROSTATE' and xtype = 'PK')
ALTER TABLE [dbo].[MetroState] WITH NOCHECK ADD 
CONSTRAINT [PK_METROSTATE] PRIMARY KEY CLUSTERED
(
	[MetroId],
	[StateId]
)
GO
--PRIMARY KEY FOR TABLE [MetroZip]
if not exists(select * from sysobjects where name = 'PK_METROZIP' and xtype = 'PK')
ALTER TABLE [dbo].[MetroZip] WITH NOCHECK ADD 
CONSTRAINT [PK_METROZIP] PRIMARY KEY CLUSTERED
(
	[MetroId],
	[ZipId]
)
GO
--PRIMARY KEY FOR TABLE [Model]
if not exists(select * from sysobjects where name = 'PK_MODEL' and xtype = 'PK')
ALTER TABLE [dbo].[Model] WITH NOCHECK ADD 
CONSTRAINT [PK_MODEL] PRIMARY KEY CLUSTERED
(
	[ModelId]
)
GO
--PRIMARY KEY FOR TABLE [SearchSaved]
if not exists(select * from sysobjects where name = 'PK_SEARCHSAVED' and xtype = 'PK')
ALTER TABLE [dbo].[SearchSaved] WITH NOCHECK ADD 
CONSTRAINT [PK_SEARCHSAVED] PRIMARY KEY CLUSTERED
(
	[SearchSavedId]
)
GO
--PRIMARY KEY FOR TABLE [SearchSavedCriteria]
if not exists(select * from sysobjects where name = 'PK_SEARCHSAVEDCRITERIA' and xtype = 'PK')
ALTER TABLE [dbo].[SearchSavedCriteria] WITH NOCHECK ADD 
CONSTRAINT [PK_SEARCHSAVEDCRITERIA] PRIMARY KEY CLUSTERED
(
	[SearchSavedCriteriaId]
)
GO
--PRIMARY KEY FOR TABLE [State]
if not exists(select * from sysobjects where name = 'PK_STATE' and xtype = 'PK')
ALTER TABLE [dbo].[State] WITH NOCHECK ADD 
CONSTRAINT [PK_STATE] PRIMARY KEY CLUSTERED
(
	[StateId]
)
GO
--PRIMARY KEY FOR TABLE [Transmission]
if not exists(select * from sysobjects where name = 'PK_TRANSMISSION' and xtype = 'PK')
ALTER TABLE [dbo].[Transmission] WITH NOCHECK ADD 
CONSTRAINT [PK_TRANSMISSION] PRIMARY KEY CLUSTERED
(
	[TransmissionId]
)
GO
--PRIMARY KEY FOR TABLE [UserAccount]
if not exists(select * from sysobjects where name = 'PK_USERACCOUNT' and xtype = 'PK')
ALTER TABLE [dbo].[UserAccount] WITH NOCHECK ADD 
CONSTRAINT [PK_USERACCOUNT] PRIMARY KEY CLUSTERED
(
	[UserId]
)
GO
--PRIMARY KEY FOR TABLE [UserLoginHistory]
if not exists(select * from sysobjects where name = 'PK_USERLOGINHISTORY' and xtype = 'PK')
ALTER TABLE [dbo].[UserLoginHistory] WITH NOCHECK ADD 
CONSTRAINT [PK_USERLOGINHISTORY] PRIMARY KEY CLUSTERED
(
	[UserLoginHistoryId]
)
GO
--PRIMARY KEY FOR TABLE [UserType]
if not exists(select * from sysobjects where name = 'PK_USERTYPE' and xtype = 'PK')
ALTER TABLE [dbo].[UserType] WITH NOCHECK ADD 
CONSTRAINT [PK_USERTYPE] PRIMARY KEY CLUSTERED
(
	[UserTypeId]
)
GO
--PRIMARY KEY FOR TABLE [VistorContact]
if not exists(select * from sysobjects where name = 'PK_VISTORCONTACT' and xtype = 'PK')
ALTER TABLE [dbo].[VistorContact] WITH NOCHECK ADD 
CONSTRAINT [PK_VISTORCONTACT] PRIMARY KEY CLUSTERED
(
	[VisitorContactId]
)
GO
--PRIMARY KEY FOR TABLE [Zip]
if not exists(select * from sysobjects where name = 'PK_ZIP' and xtype = 'PK')
ALTER TABLE [dbo].[Zip] WITH NOCHECK ADD 
CONSTRAINT [PK_ZIP] PRIMARY KEY CLUSTERED
(
	[ZipId]
)
GO
--##SECTION END [CREATE PK]

--##SECTION BEGIN [AUDIT TABLES PK]

--DROP PRIMARY KEY FOR TABLE [__AUDIT__ADMINISTRATOR]
if exists(select * from sys.objects where name = 'PK___AUDIT__ADMINISTRATOR' and type = 'PK' and type_desc = 'PRIMARY_KEY_CONSTRAINT')
ALTER TABLE [dbo].[__AUDIT__ADMINISTRATOR] DROP CONSTRAINT [PK___AUDIT__ADMINISTRATOR]
GO

--DROP PRIMARY KEY FOR TABLE [__AUDIT__BODYTYPE]
if exists(select * from sys.objects where name = 'PK___AUDIT__BODYTYPE' and type = 'PK' and type_desc = 'PRIMARY_KEY_CONSTRAINT')
ALTER TABLE [dbo].[__AUDIT__BODYTYPE] DROP CONSTRAINT [PK___AUDIT__BODYTYPE]
GO

--DROP PRIMARY KEY FOR TABLE [__AUDIT__BULLETPOINT]
if exists(select * from sys.objects where name = 'PK___AUDIT__BULLETPOINT' and type = 'PK' and type_desc = 'PRIMARY_KEY_CONSTRAINT')
ALTER TABLE [dbo].[__AUDIT__BULLETPOINT] DROP CONSTRAINT [PK___AUDIT__BULLETPOINT]
GO

--DROP PRIMARY KEY FOR TABLE [__AUDIT__CITY]
if exists(select * from sys.objects where name = 'PK___AUDIT__CITY' and type = 'PK' and type_desc = 'PRIMARY_KEY_CONSTRAINT')
ALTER TABLE [dbo].[__AUDIT__CITY] DROP CONSTRAINT [PK___AUDIT__CITY]
GO

--DROP PRIMARY KEY FOR TABLE [__AUDIT__CITYZIP]
if exists(select * from sys.objects where name = 'PK___AUDIT__CITYZIP' and type = 'PK' and type_desc = 'PRIMARY_KEY_CONSTRAINT')
ALTER TABLE [dbo].[__AUDIT__CITYZIP] DROP CONSTRAINT [PK___AUDIT__CITYZIP]
GO

--DROP PRIMARY KEY FOR TABLE [__AUDIT__COLOR]
if exists(select * from sys.objects where name = 'PK___AUDIT__COLOR' and type = 'PK' and type_desc = 'PRIMARY_KEY_CONSTRAINT')
ALTER TABLE [dbo].[__AUDIT__COLOR] DROP CONSTRAINT [PK___AUDIT__COLOR]
GO

--DROP PRIMARY KEY FOR TABLE [__AUDIT__CONDITION]
if exists(select * from sys.objects where name = 'PK___AUDIT__CONDITION' and type = 'PK' and type_desc = 'PRIMARY_KEY_CONSTRAINT')
ALTER TABLE [dbo].[__AUDIT__CONDITION] DROP CONSTRAINT [PK___AUDIT__CONDITION]
GO

--DROP PRIMARY KEY FOR TABLE [__AUDIT__CONFIGSETTING]
if exists(select * from sys.objects where name = 'PK___AUDIT__CONFIGSETTING' and type = 'PK' and type_desc = 'PRIMARY_KEY_CONSTRAINT')
ALTER TABLE [dbo].[__AUDIT__CONFIGSETTING] DROP CONSTRAINT [PK___AUDIT__CONFIGSETTING]
GO

--DROP PRIMARY KEY FOR TABLE [__AUDIT__DEALER]
if exists(select * from sys.objects where name = 'PK___AUDIT__DEALER' and type = 'PK' and type_desc = 'PRIMARY_KEY_CONSTRAINT')
ALTER TABLE [dbo].[__AUDIT__DEALER] DROP CONSTRAINT [PK___AUDIT__DEALER]
GO

--DROP PRIMARY KEY FOR TABLE [__AUDIT__FEATURE]
if exists(select * from sys.objects where name = 'PK___AUDIT__FEATURE' and type = 'PK' and type_desc = 'PRIMARY_KEY_CONSTRAINT')
ALTER TABLE [dbo].[__AUDIT__FEATURE] DROP CONSTRAINT [PK___AUDIT__FEATURE]
GO

--DROP PRIMARY KEY FOR TABLE [__AUDIT__FUELTYPE]
if exists(select * from sys.objects where name = 'PK___AUDIT__FUELTYPE' and type = 'PK' and type_desc = 'PRIMARY_KEY_CONSTRAINT')
ALTER TABLE [dbo].[__AUDIT__FUELTYPE] DROP CONSTRAINT [PK___AUDIT__FUELTYPE]
GO

--DROP PRIMARY KEY FOR TABLE [__AUDIT__LISTING]
if exists(select * from sys.objects where name = 'PK___AUDIT__LISTING' and type = 'PK' and type_desc = 'PRIMARY_KEY_CONSTRAINT')
ALTER TABLE [dbo].[__AUDIT__LISTING] DROP CONSTRAINT [PK___AUDIT__LISTING]
GO

--DROP PRIMARY KEY FOR TABLE [__AUDIT__LISTINGFEATURE]
if exists(select * from sys.objects where name = 'PK___AUDIT__LISTINGFEATURE' and type = 'PK' and type_desc = 'PRIMARY_KEY_CONSTRAINT')
ALTER TABLE [dbo].[__AUDIT__LISTINGFEATURE] DROP CONSTRAINT [PK___AUDIT__LISTINGFEATURE]
GO

--DROP PRIMARY KEY FOR TABLE [__AUDIT__LISTINGIMAGE]
if exists(select * from sys.objects where name = 'PK___AUDIT__LISTINGIMAGE' and type = 'PK' and type_desc = 'PRIMARY_KEY_CONSTRAINT')
ALTER TABLE [dbo].[__AUDIT__LISTINGIMAGE] DROP CONSTRAINT [PK___AUDIT__LISTINGIMAGE]
GO

--DROP PRIMARY KEY FOR TABLE [__AUDIT__LISTINGPREMIUM]
if exists(select * from sys.objects where name = 'PK___AUDIT__LISTINGPREMIUM' and type = 'PK' and type_desc = 'PRIMARY_KEY_CONSTRAINT')
ALTER TABLE [dbo].[__AUDIT__LISTINGPREMIUM] DROP CONSTRAINT [PK___AUDIT__LISTINGPREMIUM]
GO

--DROP PRIMARY KEY FOR TABLE [__AUDIT__LISTINGSAVED]
if exists(select * from sys.objects where name = 'PK___AUDIT__LISTINGSAVED' and type = 'PK' and type_desc = 'PRIMARY_KEY_CONSTRAINT')
ALTER TABLE [dbo].[__AUDIT__LISTINGSAVED] DROP CONSTRAINT [PK___AUDIT__LISTINGSAVED]
GO

--DROP PRIMARY KEY FOR TABLE [__AUDIT__LISTINGVIEW]
if exists(select * from sys.objects where name = 'PK___AUDIT__LISTINGVIEW' and type = 'PK' and type_desc = 'PRIMARY_KEY_CONSTRAINT')
ALTER TABLE [dbo].[__AUDIT__LISTINGVIEW] DROP CONSTRAINT [PK___AUDIT__LISTINGVIEW]
GO

--DROP PRIMARY KEY FOR TABLE [__AUDIT__MAKE]
if exists(select * from sys.objects where name = 'PK___AUDIT__MAKE' and type = 'PK' and type_desc = 'PRIMARY_KEY_CONSTRAINT')
ALTER TABLE [dbo].[__AUDIT__MAKE] DROP CONSTRAINT [PK___AUDIT__MAKE]
GO

--DROP PRIMARY KEY FOR TABLE [__AUDIT__MAKEMODEL]
if exists(select * from sys.objects where name = 'PK___AUDIT__MAKEMODEL' and type = 'PK' and type_desc = 'PRIMARY_KEY_CONSTRAINT')
ALTER TABLE [dbo].[__AUDIT__MAKEMODEL] DROP CONSTRAINT [PK___AUDIT__MAKEMODEL]
GO

--DROP PRIMARY KEY FOR TABLE [__AUDIT__METRO]
if exists(select * from sys.objects where name = 'PK___AUDIT__METRO' and type = 'PK' and type_desc = 'PRIMARY_KEY_CONSTRAINT')
ALTER TABLE [dbo].[__AUDIT__METRO] DROP CONSTRAINT [PK___AUDIT__METRO]
GO

--DROP PRIMARY KEY FOR TABLE [__AUDIT__METROSTATE]
if exists(select * from sys.objects where name = 'PK___AUDIT__METROSTATE' and type = 'PK' and type_desc = 'PRIMARY_KEY_CONSTRAINT')
ALTER TABLE [dbo].[__AUDIT__METROSTATE] DROP CONSTRAINT [PK___AUDIT__METROSTATE]
GO

--DROP PRIMARY KEY FOR TABLE [__AUDIT__METROZIP]
if exists(select * from sys.objects where name = 'PK___AUDIT__METROZIP' and type = 'PK' and type_desc = 'PRIMARY_KEY_CONSTRAINT')
ALTER TABLE [dbo].[__AUDIT__METROZIP] DROP CONSTRAINT [PK___AUDIT__METROZIP]
GO

--DROP PRIMARY KEY FOR TABLE [__AUDIT__MODEL]
if exists(select * from sys.objects where name = 'PK___AUDIT__MODEL' and type = 'PK' and type_desc = 'PRIMARY_KEY_CONSTRAINT')
ALTER TABLE [dbo].[__AUDIT__MODEL] DROP CONSTRAINT [PK___AUDIT__MODEL]
GO

--DROP PRIMARY KEY FOR TABLE [__AUDIT__SEARCHSAVED]
if exists(select * from sys.objects where name = 'PK___AUDIT__SEARCHSAVED' and type = 'PK' and type_desc = 'PRIMARY_KEY_CONSTRAINT')
ALTER TABLE [dbo].[__AUDIT__SEARCHSAVED] DROP CONSTRAINT [PK___AUDIT__SEARCHSAVED]
GO

--DROP PRIMARY KEY FOR TABLE [__AUDIT__SEARCHSAVEDCRITERIA]
if exists(select * from sys.objects where name = 'PK___AUDIT__SEARCHSAVEDCRITERIA' and type = 'PK' and type_desc = 'PRIMARY_KEY_CONSTRAINT')
ALTER TABLE [dbo].[__AUDIT__SEARCHSAVEDCRITERIA] DROP CONSTRAINT [PK___AUDIT__SEARCHSAVEDCRITERIA]
GO

--DROP PRIMARY KEY FOR TABLE [__AUDIT__STATE]
if exists(select * from sys.objects where name = 'PK___AUDIT__STATE' and type = 'PK' and type_desc = 'PRIMARY_KEY_CONSTRAINT')
ALTER TABLE [dbo].[__AUDIT__STATE] DROP CONSTRAINT [PK___AUDIT__STATE]
GO

--DROP PRIMARY KEY FOR TABLE [__AUDIT__TRANSMISSION]
if exists(select * from sys.objects where name = 'PK___AUDIT__TRANSMISSION' and type = 'PK' and type_desc = 'PRIMARY_KEY_CONSTRAINT')
ALTER TABLE [dbo].[__AUDIT__TRANSMISSION] DROP CONSTRAINT [PK___AUDIT__TRANSMISSION]
GO

--DROP PRIMARY KEY FOR TABLE [__AUDIT__USERACCOUNT]
if exists(select * from sys.objects where name = 'PK___AUDIT__USERACCOUNT' and type = 'PK' and type_desc = 'PRIMARY_KEY_CONSTRAINT')
ALTER TABLE [dbo].[__AUDIT__USERACCOUNT] DROP CONSTRAINT [PK___AUDIT__USERACCOUNT]
GO

--DROP PRIMARY KEY FOR TABLE [__AUDIT__USERLOGINHISTORY]
if exists(select * from sys.objects where name = 'PK___AUDIT__USERLOGINHISTORY' and type = 'PK' and type_desc = 'PRIMARY_KEY_CONSTRAINT')
ALTER TABLE [dbo].[__AUDIT__USERLOGINHISTORY] DROP CONSTRAINT [PK___AUDIT__USERLOGINHISTORY]
GO

--DROP PRIMARY KEY FOR TABLE [__AUDIT__USERTYPE]
if exists(select * from sys.objects where name = 'PK___AUDIT__USERTYPE' and type = 'PK' and type_desc = 'PRIMARY_KEY_CONSTRAINT')
ALTER TABLE [dbo].[__AUDIT__USERTYPE] DROP CONSTRAINT [PK___AUDIT__USERTYPE]
GO

--DROP PRIMARY KEY FOR TABLE [__AUDIT__VISTORCONTACT]
if exists(select * from sys.objects where name = 'PK___AUDIT__VISTORCONTACT' and type = 'PK' and type_desc = 'PRIMARY_KEY_CONSTRAINT')
ALTER TABLE [dbo].[__AUDIT__VISTORCONTACT] DROP CONSTRAINT [PK___AUDIT__VISTORCONTACT]
GO

--DROP PRIMARY KEY FOR TABLE [__AUDIT__ZIP]
if exists(select * from sys.objects where name = 'PK___AUDIT__ZIP' and type = 'PK' and type_desc = 'PRIMARY_KEY_CONSTRAINT')
ALTER TABLE [dbo].[__AUDIT__ZIP] DROP CONSTRAINT [PK___AUDIT__ZIP]
GO

--##SECTION END [AUDIT TABLES PK]

--FOREIGN KEY RELATIONSHIP [Listing] -> [BulletPoint] ([Listing].[ListingId] -> [BulletPoint].[ListingId])
if not exists(select * from sysobjects where name = 'FK__BULLETPOINT_LISTING' and xtype = 'F')
ALTER TABLE [dbo].[BulletPoint] ADD 
CONSTRAINT [FK__BULLETPOINT_LISTING] FOREIGN KEY 
(
	[ListingId]
) REFERENCES [dbo].[Listing] (
	[ListingId]
)
GO

--FOREIGN KEY RELATIONSHIP [State] -> [City] ([State].[StateId] -> [City].[StateId])
if not exists(select * from sysobjects where name = 'FK__CITY_STATE' and xtype = 'F')
ALTER TABLE [dbo].[City] ADD 
CONSTRAINT [FK__CITY_STATE] FOREIGN KEY 
(
	[StateId]
) REFERENCES [dbo].[State] (
	[StateId]
)
GO

--FOREIGN KEY RELATIONSHIP [City] -> [CityZip] ([City].[CityId] -> [CityZip].[CityId])
if not exists(select * from sysobjects where name = 'FK__CITYZIP_CITY' and xtype = 'F')
ALTER TABLE [dbo].[CityZip] ADD 
CONSTRAINT [FK__CITYZIP_CITY] FOREIGN KEY 
(
	[CityId]
) REFERENCES [dbo].[City] (
	[CityId]
)
GO

--FOREIGN KEY RELATIONSHIP [Zip] -> [CityZip] ([Zip].[ZipId] -> [CityZip].[ZipId])
if not exists(select * from sysobjects where name = 'FK__CITYZIP_ZIP' and xtype = 'F')
ALTER TABLE [dbo].[CityZip] ADD 
CONSTRAINT [FK__CITYZIP_ZIP] FOREIGN KEY 
(
	[ZipId]
) REFERENCES [dbo].[Zip] (
	[ZipId]
)
GO

--FOREIGN KEY RELATIONSHIP [Metro] -> [Dealer] ([Metro].[MetroId] -> [Dealer].[MetroId])
if not exists(select * from sysobjects where name = 'FK__DEALER_METRO' and xtype = 'F')
ALTER TABLE [dbo].[Dealer] ADD 
CONSTRAINT [FK__DEALER_METRO] FOREIGN KEY 
(
	[MetroId]
) REFERENCES [dbo].[Metro] (
	[MetroId]
)
GO

--FOREIGN KEY RELATIONSHIP [UserAccount] -> [Dealer] ([UserAccount].[UserId] -> [Dealer].[UserId])
if not exists(select * from sysobjects where name = 'FK__DEALER_USERACCOUNT' and xtype = 'F')
ALTER TABLE [dbo].[Dealer] ADD 
CONSTRAINT [FK__DEALER_USERACCOUNT] FOREIGN KEY 
(
	[UserId]
) REFERENCES [dbo].[UserAccount] (
	[UserId]
)
GO

--FOREIGN KEY RELATIONSHIP [BodyType] -> [Listing] ([BodyType].[BodyTypeId] -> [Listing].[BodyTypeId])
if not exists(select * from sysobjects where name = 'FK__LISTING_BODYTYPE' and xtype = 'F')
ALTER TABLE [dbo].[Listing] ADD 
CONSTRAINT [FK__LISTING_BODYTYPE] FOREIGN KEY 
(
	[BodyTypeId]
) REFERENCES [dbo].[BodyType] (
	[BodyTypeId]
)
GO

--FOREIGN KEY RELATIONSHIP [Color] -> [Listing] ([Color].[ColorId] -> [Listing].[ColorExtId])
if not exists(select * from sysobjects where name = 'FK_EXTERIOR_LISTING_COLOR' and xtype = 'F')
ALTER TABLE [dbo].[Listing] ADD 
CONSTRAINT [FK_EXTERIOR_LISTING_COLOR] FOREIGN KEY 
(
	[ColorExtId]
) REFERENCES [dbo].[Color] (
	[ColorId]
)
GO

--FOREIGN KEY RELATIONSHIP [Color] -> [Listing] ([Color].[ColorId] -> [Listing].[ColorIntId])
if not exists(select * from sysobjects where name = 'FK_INTERIOR_LISTING_COLOR' and xtype = 'F')
ALTER TABLE [dbo].[Listing] ADD 
CONSTRAINT [FK_INTERIOR_LISTING_COLOR] FOREIGN KEY 
(
	[ColorIntId]
) REFERENCES [dbo].[Color] (
	[ColorId]
)
GO

--FOREIGN KEY RELATIONSHIP [Condition] -> [Listing] ([Condition].[ConditionId] -> [Listing].[ConditionId])
if not exists(select * from sysobjects where name = 'FK__LISTING_CONDITION' and xtype = 'F')
ALTER TABLE [dbo].[Listing] ADD 
CONSTRAINT [FK__LISTING_CONDITION] FOREIGN KEY 
(
	[ConditionId]
) REFERENCES [dbo].[Condition] (
	[ConditionId]
)
GO

--FOREIGN KEY RELATIONSHIP [FuelType] -> [Listing] ([FuelType].[FuelTypeId] -> [Listing].[FuelTypeId])
if not exists(select * from sysobjects where name = 'FK__LISTING_FUELTYPE' and xtype = 'F')
ALTER TABLE [dbo].[Listing] ADD 
CONSTRAINT [FK__LISTING_FUELTYPE] FOREIGN KEY 
(
	[FuelTypeId]
) REFERENCES [dbo].[FuelType] (
	[FuelTypeId]
)
GO

--FOREIGN KEY RELATIONSHIP [MakeModel] -> [Listing] ([MakeModel].[MakeModelId] -> [Listing].[MakeModelId])
if not exists(select * from sysobjects where name = 'FK__LISTING_MAKEMODEL' and xtype = 'F')
ALTER TABLE [dbo].[Listing] ADD 
CONSTRAINT [FK__LISTING_MAKEMODEL] FOREIGN KEY 
(
	[MakeModelId]
) REFERENCES [dbo].[MakeModel] (
	[MakeModelId]
)
GO

--FOREIGN KEY RELATIONSHIP [Metro] -> [Listing] ([Metro].[MetroId] -> [Listing].[MetroId])
if not exists(select * from sysobjects where name = 'FK__LISTING_METRO' and xtype = 'F')
ALTER TABLE [dbo].[Listing] ADD 
CONSTRAINT [FK__LISTING_METRO] FOREIGN KEY 
(
	[MetroId]
) REFERENCES [dbo].[Metro] (
	[MetroId]
)
GO

--FOREIGN KEY RELATIONSHIP [Transmission] -> [Listing] ([Transmission].[TransmissionId] -> [Listing].[TransmissionId])
if not exists(select * from sysobjects where name = 'FK__LISTING_TRANSMISSION' and xtype = 'F')
ALTER TABLE [dbo].[Listing] ADD 
CONSTRAINT [FK__LISTING_TRANSMISSION] FOREIGN KEY 
(
	[TransmissionId]
) REFERENCES [dbo].[Transmission] (
	[TransmissionId]
)
GO

--FOREIGN KEY RELATIONSHIP [UserAccount] -> [Listing] ([UserAccount].[UserId] -> [Listing].[UserId])
if not exists(select * from sysobjects where name = 'FK__LISTING_USERACCOUNT' and xtype = 'F')
ALTER TABLE [dbo].[Listing] ADD 
CONSTRAINT [FK__LISTING_USERACCOUNT] FOREIGN KEY 
(
	[UserId]
) REFERENCES [dbo].[UserAccount] (
	[UserId]
)
GO

--FOREIGN KEY RELATIONSHIP [Feature] -> [ListingFeature] ([Feature].[FeatureId] -> [ListingFeature].[FeatureId])
if not exists(select * from sysobjects where name = 'FK__LISTINGFEATURE_FEATURE' and xtype = 'F')
ALTER TABLE [dbo].[ListingFeature] ADD 
CONSTRAINT [FK__LISTINGFEATURE_FEATURE] FOREIGN KEY 
(
	[FeatureId]
) REFERENCES [dbo].[Feature] (
	[FeatureId]
)
GO

--FOREIGN KEY RELATIONSHIP [Listing] -> [ListingFeature] ([Listing].[ListingId] -> [ListingFeature].[ListingId])
if not exists(select * from sysobjects where name = 'FK__LISTINGFEATURE_LISTING' and xtype = 'F')
ALTER TABLE [dbo].[ListingFeature] ADD 
CONSTRAINT [FK__LISTINGFEATURE_LISTING] FOREIGN KEY 
(
	[ListingId]
) REFERENCES [dbo].[Listing] (
	[ListingId]
)
GO

--FOREIGN KEY RELATIONSHIP [Listing] -> [ListingImage] ([Listing].[ListingId] -> [ListingImage].[ListingId])
if not exists(select * from sysobjects where name = 'FK__LISTINGIMAGE_LISTING' and xtype = 'F')
ALTER TABLE [dbo].[ListingImage] ADD 
CONSTRAINT [FK__LISTINGIMAGE_LISTING] FOREIGN KEY 
(
	[ListingId]
) REFERENCES [dbo].[Listing] (
	[ListingId]
)
GO

--FOREIGN KEY RELATIONSHIP [Listing] -> [ListingPremium] ([Listing].[ListingId] -> [ListingPremium].[ListingId])
if not exists(select * from sysobjects where name = 'FK__LISTINGPREMIUM_LISTING' and xtype = 'F')
ALTER TABLE [dbo].[ListingPremium] ADD 
CONSTRAINT [FK__LISTINGPREMIUM_LISTING] FOREIGN KEY 
(
	[ListingId]
) REFERENCES [dbo].[Listing] (
	[ListingId]
)
GO

--FOREIGN KEY RELATIONSHIP [Listing] -> [ListingSaved] ([Listing].[ListingId] -> [ListingSaved].[ListingId])
if not exists(select * from sysobjects where name = 'FK__LISTINGSAVED_LISTING' and xtype = 'F')
ALTER TABLE [dbo].[ListingSaved] ADD 
CONSTRAINT [FK__LISTINGSAVED_LISTING] FOREIGN KEY 
(
	[ListingId]
) REFERENCES [dbo].[Listing] (
	[ListingId]
)
GO

--FOREIGN KEY RELATIONSHIP [UserAccount] -> [ListingSaved] ([UserAccount].[UserId] -> [ListingSaved].[UserId])
if not exists(select * from sysobjects where name = 'FK__LISTINGSAVED_USERACCOUNT' and xtype = 'F')
ALTER TABLE [dbo].[ListingSaved] ADD 
CONSTRAINT [FK__LISTINGSAVED_USERACCOUNT] FOREIGN KEY 
(
	[UserId]
) REFERENCES [dbo].[UserAccount] (
	[UserId]
)
GO

--FOREIGN KEY RELATIONSHIP [Listing] -> [ListingView] ([Listing].[ListingId] -> [ListingView].[ListingId])
if not exists(select * from sysobjects where name = 'FK__LISTINGVIEW_LISTING' and xtype = 'F')
ALTER TABLE [dbo].[ListingView] ADD 
CONSTRAINT [FK__LISTINGVIEW_LISTING] FOREIGN KEY 
(
	[ListingId]
) REFERENCES [dbo].[Listing] (
	[ListingId]
)
GO

--FOREIGN KEY RELATIONSHIP [Make] -> [MakeModel] ([Make].[MakeId] -> [MakeModel].[MakeId])
if not exists(select * from sysobjects where name = 'FK__MAKEMODEL_MAKE' and xtype = 'F')
ALTER TABLE [dbo].[MakeModel] ADD 
CONSTRAINT [FK__MAKEMODEL_MAKE] FOREIGN KEY 
(
	[MakeId]
) REFERENCES [dbo].[Make] (
	[MakeId]
)
GO

--FOREIGN KEY RELATIONSHIP [Model] -> [MakeModel] ([Model].[ModelId] -> [MakeModel].[ModelId])
if not exists(select * from sysobjects where name = 'FK__MAKEMODEL_MODEL' and xtype = 'F')
ALTER TABLE [dbo].[MakeModel] ADD 
CONSTRAINT [FK__MAKEMODEL_MODEL] FOREIGN KEY 
(
	[ModelId]
) REFERENCES [dbo].[Model] (
	[ModelId]
)
GO

--FOREIGN KEY RELATIONSHIP [Metro] -> [MetroState] ([Metro].[MetroId] -> [MetroState].[MetroId])
if not exists(select * from sysobjects where name = 'FK__METROSTATE_METRO' and xtype = 'F')
ALTER TABLE [dbo].[MetroState] ADD 
CONSTRAINT [FK__METROSTATE_METRO] FOREIGN KEY 
(
	[MetroId]
) REFERENCES [dbo].[Metro] (
	[MetroId]
)
GO

--FOREIGN KEY RELATIONSHIP [State] -> [MetroState] ([State].[StateId] -> [MetroState].[StateId])
if not exists(select * from sysobjects where name = 'FK__METROSTATE_STATE' and xtype = 'F')
ALTER TABLE [dbo].[MetroState] ADD 
CONSTRAINT [FK__METROSTATE_STATE] FOREIGN KEY 
(
	[StateId]
) REFERENCES [dbo].[State] (
	[StateId]
)
GO

--FOREIGN KEY RELATIONSHIP [Metro] -> [MetroZip] ([Metro].[MetroId] -> [MetroZip].[MetroId])
if not exists(select * from sysobjects where name = 'FK__METROZIP_METRO' and xtype = 'F')
ALTER TABLE [dbo].[MetroZip] ADD 
CONSTRAINT [FK__METROZIP_METRO] FOREIGN KEY 
(
	[MetroId]
) REFERENCES [dbo].[Metro] (
	[MetroId]
)
GO

--FOREIGN KEY RELATIONSHIP [Zip] -> [MetroZip] ([Zip].[ZipId] -> [MetroZip].[ZipId])
if not exists(select * from sysobjects where name = 'FK__METROZIP_ZIP' and xtype = 'F')
ALTER TABLE [dbo].[MetroZip] ADD 
CONSTRAINT [FK__METROZIP_ZIP] FOREIGN KEY 
(
	[ZipId]
) REFERENCES [dbo].[Zip] (
	[ZipId]
)
GO

--FOREIGN KEY RELATIONSHIP [UserAccount] -> [SearchSaved] ([UserAccount].[UserId] -> [SearchSaved].[UserId])
if not exists(select * from sysobjects where name = 'FK__SEARCHSAVED_USERACCOUNT' and xtype = 'F')
ALTER TABLE [dbo].[SearchSaved] ADD 
CONSTRAINT [FK__SEARCHSAVED_USERACCOUNT] FOREIGN KEY 
(
	[UserId]
) REFERENCES [dbo].[UserAccount] (
	[UserId]
)
GO

--FOREIGN KEY RELATIONSHIP [SearchSaved] -> [SearchSavedCriteria] ([SearchSaved].[SearchSavedId] -> [SearchSavedCriteria].[SearchSavedId])
if not exists(select * from sysobjects where name = 'FK__SEARCHSAVEDCRITERIA_SEARCHSAVED' and xtype = 'F')
ALTER TABLE [dbo].[SearchSavedCriteria] ADD 
CONSTRAINT [FK__SEARCHSAVEDCRITERIA_SEARCHSAVED] FOREIGN KEY 
(
	[SearchSavedId]
) REFERENCES [dbo].[SearchSaved] (
	[SearchSavedId]
)
GO

--FOREIGN KEY RELATIONSHIP [State] -> [UserAccount] ([State].[StateId] -> [UserAccount].[StateId])
if not exists(select * from sysobjects where name = 'FK__USERACCOUNT_STATE' and xtype = 'F')
ALTER TABLE [dbo].[UserAccount] ADD 
CONSTRAINT [FK__USERACCOUNT_STATE] FOREIGN KEY 
(
	[StateId]
) REFERENCES [dbo].[State] (
	[StateId]
)
GO

--FOREIGN KEY RELATIONSHIP [UserType] -> [UserAccount] ([UserType].[UserTypeId] -> [UserAccount].[UserTypeId])
if not exists(select * from sysobjects where name = 'FK__USERACCOUNT_USERTYPE' and xtype = 'F')
ALTER TABLE [dbo].[UserAccount] ADD 
CONSTRAINT [FK__USERACCOUNT_USERTYPE] FOREIGN KEY 
(
	[UserTypeId]
) REFERENCES [dbo].[UserType] (
	[UserTypeId]
)
GO

--FOREIGN KEY RELATIONSHIP [Zip] -> [UserAccount] ([Zip].[ZipId] -> [UserAccount].[ZipId])
if not exists(select * from sysobjects where name = 'FK__USERACCOUNT_ZIP' and xtype = 'F')
ALTER TABLE [dbo].[UserAccount] ADD 
CONSTRAINT [FK__USERACCOUNT_ZIP] FOREIGN KEY 
(
	[ZipId]
) REFERENCES [dbo].[Zip] (
	[ZipId]
)
GO

--FOREIGN KEY RELATIONSHIP [UserAccount] -> [UserLoginHistory] ([UserAccount].[UserId] -> [UserLoginHistory].[UserId])
if not exists(select * from sysobjects where name = 'FK__USERLOGINHISTORY_USERACCOUNT' and xtype = 'F')
ALTER TABLE [dbo].[UserLoginHistory] ADD 
CONSTRAINT [FK__USERLOGINHISTORY_USERACCOUNT] FOREIGN KEY 
(
	[UserId]
) REFERENCES [dbo].[UserAccount] (
	[UserId]
)
GO

--FOREIGN KEY RELATIONSHIP [UserAccount] -> [VistorContact] ([UserAccount].[UserId] -> [VistorContact].[UserId])
if not exists(select * from sysobjects where name = 'FK__VISTORCONTACT_USERACCOUNT' and xtype = 'F')
ALTER TABLE [dbo].[VistorContact] ADD 
CONSTRAINT [FK__VISTORCONTACT_USERACCOUNT] FOREIGN KEY 
(
	[UserId]
) REFERENCES [dbo].[UserAccount] (
	[UserId]
)
GO

--FOREIGN KEY RELATIONSHIP [State] -> [Zip] ([State].[StateId] -> [Zip].[StateId])
if not exists(select * from sysobjects where name = 'FK__ZIP_STATE' and xtype = 'F')
ALTER TABLE [dbo].[Zip] ADD 
CONSTRAINT [FK__ZIP_STATE] FOREIGN KEY 
(
	[StateId]
) REFERENCES [dbo].[State] (
	[StateId]
)
GO

--##SECTION BEGIN [CREATE INDEXES]

--DELETE INDEX
if exists(select * from sys.indexes where name = 'IDX_ADMINISTRATOR_EMAIL' and type_desc = 'CLUSTERED')
DROP INDEX [IDX_ADMINISTRATOR_EMAIL] ON [dbo].[Administrator]
GO

--INDEX FOR TABLE [Administrator] COLUMNS:[Email]
if not exists(select * from sys.indexes where name = 'IDX_ADMINISTRATOR_EMAIL')
CREATE NONCLUSTERED INDEX [IDX_ADMINISTRATOR_EMAIL] ON [dbo].[Administrator] ([Email] ASC)
GO

--DELETE INDEX
if exists(select * from sys.indexes where name = 'IDX_ADMINISTRATOR_FIRSTNAME' and type_desc = 'CLUSTERED')
DROP INDEX [IDX_ADMINISTRATOR_FIRSTNAME] ON [dbo].[Administrator]
GO

--INDEX FOR TABLE [Administrator] COLUMNS:[FirstName]
if not exists(select * from sys.indexes where name = 'IDX_ADMINISTRATOR_FIRSTNAME')
CREATE NONCLUSTERED INDEX [IDX_ADMINISTRATOR_FIRSTNAME] ON [dbo].[Administrator] ([FirstName] ASC)
GO

--DELETE INDEX
if exists(select * from sys.indexes where name = 'IDX_ADMINISTRATOR_LASTNAME' and type_desc = 'CLUSTERED')
DROP INDEX [IDX_ADMINISTRATOR_LASTNAME] ON [dbo].[Administrator]
GO

--INDEX FOR TABLE [Administrator] COLUMNS:[LastName]
if not exists(select * from sys.indexes where name = 'IDX_ADMINISTRATOR_LASTNAME')
CREATE NONCLUSTERED INDEX [IDX_ADMINISTRATOR_LASTNAME] ON [dbo].[Administrator] ([LastName] ASC)
GO

--DELETE INDEX
if exists(select * from sys.indexes where name = 'IDX_ADMINISTRATOR_USERNAME' and type_desc = 'CLUSTERED')
DROP INDEX [IDX_ADMINISTRATOR_USERNAME] ON [dbo].[Administrator]
GO

--INDEX FOR TABLE [Administrator] COLUMNS:[UserName]
if not exists(select * from sys.indexes where name = 'IDX_ADMINISTRATOR_USERNAME')
CREATE NONCLUSTERED INDEX [IDX_ADMINISTRATOR_USERNAME] ON [dbo].[Administrator] ([UserName] ASC)
GO

--DELETE INDEX
if exists(select * from sys.indexes where name = 'IDX_BULLETPOINT_LISTINGID' and type_desc = 'CLUSTERED')
DROP INDEX [IDX_BULLETPOINT_LISTINGID] ON [dbo].[BulletPoint]
GO

--INDEX FOR TABLE [BulletPoint] COLUMNS:[ListingId]
if not exists(select * from sys.indexes where name = 'IDX_BULLETPOINT_LISTINGID')
CREATE NONCLUSTERED INDEX [IDX_BULLETPOINT_LISTINGID] ON [dbo].[BulletPoint] ([ListingId] ASC)
GO

--DELETE INDEX
if exists(select * from sys.indexes where name = 'IDX_BULLETPOINT_TEXT' and type_desc = 'CLUSTERED')
DROP INDEX [IDX_BULLETPOINT_TEXT] ON [dbo].[BulletPoint]
GO

--INDEX FOR TABLE [BulletPoint] COLUMNS:[Text]
if not exists(select * from sys.indexes where name = 'IDX_BULLETPOINT_TEXT')
CREATE NONCLUSTERED INDEX [IDX_BULLETPOINT_TEXT] ON [dbo].[BulletPoint] ([Text] ASC)
GO

--DELETE INDEX
if exists(select * from sys.indexes where name = 'IDX_COLOR_NAME' and type_desc = 'CLUSTERED')
DROP INDEX [IDX_COLOR_NAME] ON [dbo].[Color]
GO

--INDEX FOR TABLE [Color] COLUMNS:[Name]
if not exists(select * from sys.indexes where name = 'IDX_COLOR_NAME')
CREATE NONCLUSTERED INDEX [IDX_COLOR_NAME] ON [dbo].[Color] ([Name] ASC)
GO

--DELETE INDEX
if exists(select * from sys.indexes where name = 'IDX_CONDITION_NAME' and type_desc = 'CLUSTERED')
DROP INDEX [IDX_CONDITION_NAME] ON [dbo].[Condition]
GO

--INDEX FOR TABLE [Condition] COLUMNS:[Name]
if not exists(select * from sys.indexes where name = 'IDX_CONDITION_NAME')
CREATE NONCLUSTERED INDEX [IDX_CONDITION_NAME] ON [dbo].[Condition] ([Name] ASC)
GO

--DELETE INDEX
if exists(select * from sys.indexes where name = 'IDX_DEALER_METROID' and type_desc = 'CLUSTERED')
DROP INDEX [IDX_DEALER_METROID] ON [dbo].[Dealer]
GO

--INDEX FOR TABLE [Dealer] COLUMNS:[MetroId]
if not exists(select * from sys.indexes where name = 'IDX_DEALER_METROID')
CREATE NONCLUSTERED INDEX [IDX_DEALER_METROID] ON [dbo].[Dealer] ([MetroId] ASC)
GO

--DELETE INDEX
if exists(select * from sys.indexes where name = 'IDX_FEATURE_NAME' and type_desc = 'CLUSTERED')
DROP INDEX [IDX_FEATURE_NAME] ON [dbo].[Feature]
GO

--INDEX FOR TABLE [Feature] COLUMNS:[Name]
if not exists(select * from sys.indexes where name = 'IDX_FEATURE_NAME')
CREATE NONCLUSTERED INDEX [IDX_FEATURE_NAME] ON [dbo].[Feature] ([Name] ASC)
GO

--DELETE INDEX
if exists(select * from sys.indexes where name = 'IDX_LISTING_ACTIVE' and type_desc = 'CLUSTERED')
DROP INDEX [IDX_LISTING_ACTIVE] ON [dbo].[Listing]
GO

--INDEX FOR TABLE [Listing] COLUMNS:[Active]
if not exists(select * from sys.indexes where name = 'IDX_LISTING_ACTIVE')
CREATE NONCLUSTERED INDEX [IDX_LISTING_ACTIVE] ON [dbo].[Listing] ([Active] ASC)
GO

--DELETE INDEX
if exists(select * from sys.indexes where name = 'IDX_LISTING_BODYTYPEID' and type_desc = 'CLUSTERED')
DROP INDEX [IDX_LISTING_BODYTYPEID] ON [dbo].[Listing]
GO

--INDEX FOR TABLE [Listing] COLUMNS:[BodyTypeId]
if not exists(select * from sys.indexes where name = 'IDX_LISTING_BODYTYPEID')
CREATE NONCLUSTERED INDEX [IDX_LISTING_BODYTYPEID] ON [dbo].[Listing] ([BodyTypeId] ASC)
GO

--DELETE INDEX
if exists(select * from sys.indexes where name = 'IDX_LISTING_COLOREXTID' and type_desc = 'CLUSTERED')
DROP INDEX [IDX_LISTING_COLOREXTID] ON [dbo].[Listing]
GO

--INDEX FOR TABLE [Listing] COLUMNS:[ColorExtId]
if not exists(select * from sys.indexes where name = 'IDX_LISTING_COLOREXTID')
CREATE NONCLUSTERED INDEX [IDX_LISTING_COLOREXTID] ON [dbo].[Listing] ([ColorExtId] ASC)
GO

--DELETE INDEX
if exists(select * from sys.indexes where name = 'IDX_LISTING_COLORINTID' and type_desc = 'CLUSTERED')
DROP INDEX [IDX_LISTING_COLORINTID] ON [dbo].[Listing]
GO

--INDEX FOR TABLE [Listing] COLUMNS:[ColorIntId]
if not exists(select * from sys.indexes where name = 'IDX_LISTING_COLORINTID')
CREATE NONCLUSTERED INDEX [IDX_LISTING_COLORINTID] ON [dbo].[Listing] ([ColorIntId] ASC)
GO

--DELETE INDEX
if exists(select * from sys.indexes where name = 'IDX_LISTING_CONDITIONID' and type_desc = 'CLUSTERED')
DROP INDEX [IDX_LISTING_CONDITIONID] ON [dbo].[Listing]
GO

--INDEX FOR TABLE [Listing] COLUMNS:[ConditionId]
if not exists(select * from sys.indexes where name = 'IDX_LISTING_CONDITIONID')
CREATE NONCLUSTERED INDEX [IDX_LISTING_CONDITIONID] ON [dbo].[Listing] ([ConditionId] ASC)
GO

--DELETE INDEX
if exists(select * from sys.indexes where name = 'IDX_LISTING_EXPIRATIONDATE' and type_desc = 'CLUSTERED')
DROP INDEX [IDX_LISTING_EXPIRATIONDATE] ON [dbo].[Listing]
GO

--INDEX FOR TABLE [Listing] COLUMNS:[ExpirationDate]
if not exists(select * from sys.indexes where name = 'IDX_LISTING_EXPIRATIONDATE')
CREATE NONCLUSTERED INDEX [IDX_LISTING_EXPIRATIONDATE] ON [dbo].[Listing] ([ExpirationDate] ASC)
GO

--DELETE INDEX
if exists(select * from sys.indexes where name = 'IDX_LISTING_FUELTYPEID' and type_desc = 'CLUSTERED')
DROP INDEX [IDX_LISTING_FUELTYPEID] ON [dbo].[Listing]
GO

--INDEX FOR TABLE [Listing] COLUMNS:[FuelTypeId]
if not exists(select * from sys.indexes where name = 'IDX_LISTING_FUELTYPEID')
CREATE NONCLUSTERED INDEX [IDX_LISTING_FUELTYPEID] ON [dbo].[Listing] ([FuelTypeId] ASC)
GO

--DELETE INDEX
if exists(select * from sys.indexes where name = 'IDX_LISTING_INVOICE' and type_desc = 'CLUSTERED')
DROP INDEX [IDX_LISTING_INVOICE] ON [dbo].[Listing]
GO

--INDEX FOR TABLE [Listing] COLUMNS:[Invoice]
if not exists(select * from sys.indexes where name = 'IDX_LISTING_INVOICE')
CREATE NONCLUSTERED INDEX [IDX_LISTING_INVOICE] ON [dbo].[Listing] ([Invoice] ASC)
GO

--DELETE INDEX
if exists(select * from sys.indexes where name = 'IDX_LISTING_LISTDATE' and type_desc = 'CLUSTERED')
DROP INDEX [IDX_LISTING_LISTDATE] ON [dbo].[Listing]
GO

--INDEX FOR TABLE [Listing] COLUMNS:[ListDate]
if not exists(select * from sys.indexes where name = 'IDX_LISTING_LISTDATE')
CREATE NONCLUSTERED INDEX [IDX_LISTING_LISTDATE] ON [dbo].[Listing] ([ListDate] ASC)
GO

--DELETE INDEX
if exists(select * from sys.indexes where name = 'IDX_LISTING_MAKEMODELID' and type_desc = 'CLUSTERED')
DROP INDEX [IDX_LISTING_MAKEMODELID] ON [dbo].[Listing]
GO

--INDEX FOR TABLE [Listing] COLUMNS:[MakeModelId]
if not exists(select * from sys.indexes where name = 'IDX_LISTING_MAKEMODELID')
CREATE NONCLUSTERED INDEX [IDX_LISTING_MAKEMODELID] ON [dbo].[Listing] ([MakeModelId] ASC)
GO

--DELETE INDEX
if exists(select * from sys.indexes where name = 'IDX_LISTING_METROID' and type_desc = 'CLUSTERED')
DROP INDEX [IDX_LISTING_METROID] ON [dbo].[Listing]
GO

--INDEX FOR TABLE [Listing] COLUMNS:[MetroId]
if not exists(select * from sys.indexes where name = 'IDX_LISTING_METROID')
CREATE NONCLUSTERED INDEX [IDX_LISTING_METROID] ON [dbo].[Listing] ([MetroId] ASC)
GO

--DELETE INDEX
if exists(select * from sys.indexes where name = 'IDX_LISTING_MILEAGE' and type_desc = 'CLUSTERED')
DROP INDEX [IDX_LISTING_MILEAGE] ON [dbo].[Listing]
GO

--INDEX FOR TABLE [Listing] COLUMNS:[Mileage]
if not exists(select * from sys.indexes where name = 'IDX_LISTING_MILEAGE')
CREATE NONCLUSTERED INDEX [IDX_LISTING_MILEAGE] ON [dbo].[Listing] ([Mileage] ASC)
GO

--DELETE INDEX
if exists(select * from sys.indexes where name = 'IDX_LISTING_TRANSMISSIONID' and type_desc = 'CLUSTERED')
DROP INDEX [IDX_LISTING_TRANSMISSIONID] ON [dbo].[Listing]
GO

--INDEX FOR TABLE [Listing] COLUMNS:[TransmissionId]
if not exists(select * from sys.indexes where name = 'IDX_LISTING_TRANSMISSIONID')
CREATE NONCLUSTERED INDEX [IDX_LISTING_TRANSMISSIONID] ON [dbo].[Listing] ([TransmissionId] ASC)
GO

--DELETE INDEX
if exists(select * from sys.indexes where name = 'IDX_LISTING_USERID' and type_desc = 'CLUSTERED')
DROP INDEX [IDX_LISTING_USERID] ON [dbo].[Listing]
GO

--INDEX FOR TABLE [Listing] COLUMNS:[UserId]
if not exists(select * from sys.indexes where name = 'IDX_LISTING_USERID')
CREATE NONCLUSTERED INDEX [IDX_LISTING_USERID] ON [dbo].[Listing] ([UserId] ASC)
GO

--DELETE INDEX
if exists(select * from sys.indexes where name = 'IDX_LISTING_VIN' and type_desc = 'CLUSTERED')
DROP INDEX [IDX_LISTING_VIN] ON [dbo].[Listing]
GO

--INDEX FOR TABLE [Listing] COLUMNS:[Vin]
if not exists(select * from sys.indexes where name = 'IDX_LISTING_VIN')
CREATE NONCLUSTERED INDEX [IDX_LISTING_VIN] ON [dbo].[Listing] ([Vin] ASC)
GO

--DELETE INDEX
if exists(select * from sys.indexes where name = 'IDX_LISTINGIMAGE_LISTINGID' and type_desc = 'CLUSTERED')
DROP INDEX [IDX_LISTINGIMAGE_LISTINGID] ON [dbo].[ListingImage]
GO

--INDEX FOR TABLE [ListingImage] COLUMNS:[ListingId]
if not exists(select * from sys.indexes where name = 'IDX_LISTINGIMAGE_LISTINGID')
CREATE NONCLUSTERED INDEX [IDX_LISTINGIMAGE_LISTINGID] ON [dbo].[ListingImage] ([ListingId] ASC)
GO

--DELETE INDEX
if exists(select * from sys.indexes where name = 'IDX_LISTINGPREMIUM_ACTIVE' and type_desc = 'CLUSTERED')
DROP INDEX [IDX_LISTINGPREMIUM_ACTIVE] ON [dbo].[ListingPremium]
GO

--INDEX FOR TABLE [ListingPremium] COLUMNS:[Active]
if not exists(select * from sys.indexes where name = 'IDX_LISTINGPREMIUM_ACTIVE')
CREATE NONCLUSTERED INDEX [IDX_LISTINGPREMIUM_ACTIVE] ON [dbo].[ListingPremium] ([Active] ASC)
GO

--DELETE INDEX
if exists(select * from sys.indexes where name = 'IDX_LISTINGPREMIUM_STATEID' and type_desc = 'CLUSTERED')
DROP INDEX [IDX_LISTINGPREMIUM_STATEID] ON [dbo].[ListingPremium]
GO

--INDEX FOR TABLE [ListingPremium] COLUMNS:[StateId]
if not exists(select * from sys.indexes where name = 'IDX_LISTINGPREMIUM_STATEID')
CREATE NONCLUSTERED INDEX [IDX_LISTINGPREMIUM_STATEID] ON [dbo].[ListingPremium] ([StateId] ASC)
GO

--DELETE INDEX
if exists(select * from sys.indexes where name = 'IDX_LISTINGVIEW_LISTINGID' and type_desc = 'CLUSTERED')
DROP INDEX [IDX_LISTINGVIEW_LISTINGID] ON [dbo].[ListingView]
GO

--INDEX FOR TABLE [ListingView] COLUMNS:[ListingId]
if not exists(select * from sys.indexes where name = 'IDX_LISTINGVIEW_LISTINGID')
CREATE NONCLUSTERED INDEX [IDX_LISTINGVIEW_LISTINGID] ON [dbo].[ListingView] ([ListingId] ASC)
GO

--DELETE INDEX
if exists(select * from sys.indexes where name = 'IDX_MAKE_NAME' and type_desc = 'CLUSTERED')
DROP INDEX [IDX_MAKE_NAME] ON [dbo].[Make]
GO

--INDEX FOR TABLE [Make] COLUMNS:[Name]
if not exists(select * from sys.indexes where name = 'IDX_MAKE_NAME')
CREATE NONCLUSTERED INDEX [IDX_MAKE_NAME] ON [dbo].[Make] ([Name] ASC)
GO

--DELETE INDEX
if exists(select * from sys.indexes where name = 'IDX_MAKEMODEL_MAKEID' and type_desc = 'CLUSTERED')
DROP INDEX [IDX_MAKEMODEL_MAKEID] ON [dbo].[MakeModel]
GO

--INDEX FOR TABLE [MakeModel] COLUMNS:[MakeId]
if not exists(select * from sys.indexes where name = 'IDX_MAKEMODEL_MAKEID')
CREATE NONCLUSTERED INDEX [IDX_MAKEMODEL_MAKEID] ON [dbo].[MakeModel] ([MakeId] ASC)
GO

--DELETE INDEX
if exists(select * from sys.indexes where name = 'IDX_MAKEMODEL_MODELID' and type_desc = 'CLUSTERED')
DROP INDEX [IDX_MAKEMODEL_MODELID] ON [dbo].[MakeModel]
GO

--INDEX FOR TABLE [MakeModel] COLUMNS:[ModelId]
if not exists(select * from sys.indexes where name = 'IDX_MAKEMODEL_MODELID')
CREATE NONCLUSTERED INDEX [IDX_MAKEMODEL_MODELID] ON [dbo].[MakeModel] ([ModelId] ASC)
GO

--DELETE INDEX
if exists(select * from sys.indexes where name = 'IDX_METRO_ISPOPULAR' and type_desc = 'CLUSTERED')
DROP INDEX [IDX_METRO_ISPOPULAR] ON [dbo].[Metro]
GO

--INDEX FOR TABLE [Metro] COLUMNS:[IsPopular]
if not exists(select * from sys.indexes where name = 'IDX_METRO_ISPOPULAR')
CREATE NONCLUSTERED INDEX [IDX_METRO_ISPOPULAR] ON [dbo].[Metro] ([IsPopular] ASC)
GO

--DELETE INDEX
if exists(select * from sys.indexes where name = 'IDX_METRO_NAME' and type_desc = 'CLUSTERED')
DROP INDEX [IDX_METRO_NAME] ON [dbo].[Metro]
GO

--INDEX FOR TABLE [Metro] COLUMNS:[Name]
if not exists(select * from sys.indexes where name = 'IDX_METRO_NAME')
CREATE NONCLUSTERED INDEX [IDX_METRO_NAME] ON [dbo].[Metro] ([Name] ASC)
GO

--DELETE INDEX
if exists(select * from sys.indexes where name = 'IDX_MODEL_NAME' and type_desc = 'CLUSTERED')
DROP INDEX [IDX_MODEL_NAME] ON [dbo].[Model]
GO

--INDEX FOR TABLE [Model] COLUMNS:[Name]
if not exists(select * from sys.indexes where name = 'IDX_MODEL_NAME')
CREATE NONCLUSTERED INDEX [IDX_MODEL_NAME] ON [dbo].[Model] ([Name] ASC)
GO

--DELETE INDEX
if exists(select * from sys.indexes where name = 'IDX_SEARCHSAVED_USERID' and type_desc = 'CLUSTERED')
DROP INDEX [IDX_SEARCHSAVED_USERID] ON [dbo].[SearchSaved]
GO

--INDEX FOR TABLE [SearchSaved] COLUMNS:[UserId]
if not exists(select * from sys.indexes where name = 'IDX_SEARCHSAVED_USERID')
CREATE NONCLUSTERED INDEX [IDX_SEARCHSAVED_USERID] ON [dbo].[SearchSaved] ([UserId] ASC)
GO

--DELETE INDEX
if exists(select * from sys.indexes where name = 'IDX_SEARCHSAVEDCRITERIA_SEARCHSAVEDID' and type_desc = 'CLUSTERED')
DROP INDEX [IDX_SEARCHSAVEDCRITERIA_SEARCHSAVEDID] ON [dbo].[SearchSavedCriteria]
GO

--INDEX FOR TABLE [SearchSavedCriteria] COLUMNS:[SearchSavedId]
if not exists(select * from sys.indexes where name = 'IDX_SEARCHSAVEDCRITERIA_SEARCHSAVEDID')
CREATE NONCLUSTERED INDEX [IDX_SEARCHSAVEDCRITERIA_SEARCHSAVEDID] ON [dbo].[SearchSavedCriteria] ([SearchSavedId] ASC)
GO

--DELETE INDEX
if exists(select * from sys.indexes where name = 'IDX_STATE_ABBR' and type_desc = 'CLUSTERED')
DROP INDEX [IDX_STATE_ABBR] ON [dbo].[State]
GO

--INDEX FOR TABLE [State] COLUMNS:[Abbr]
if not exists(select * from sys.indexes where name = 'IDX_STATE_ABBR')
CREATE NONCLUSTERED INDEX [IDX_STATE_ABBR] ON [dbo].[State] ([Abbr] ASC)
GO

--DELETE INDEX
if exists(select * from sys.indexes where name = 'IDX_STATE_NAME' and type_desc = 'CLUSTERED')
DROP INDEX [IDX_STATE_NAME] ON [dbo].[State]
GO

--INDEX FOR TABLE [State] COLUMNS:[Name]
if not exists(select * from sys.indexes where name = 'IDX_STATE_NAME')
CREATE NONCLUSTERED INDEX [IDX_STATE_NAME] ON [dbo].[State] ([Name] ASC)
GO

--DELETE INDEX
if exists(select * from sys.indexes where name = 'IDX_USERACCOUNT_EMAIL' and type_desc = 'CLUSTERED')
DROP INDEX [IDX_USERACCOUNT_EMAIL] ON [dbo].[UserAccount]
GO

--INDEX FOR TABLE [UserAccount] COLUMNS:[Email]
if not exists(select * from sys.indexes where name = 'IDX_USERACCOUNT_EMAIL')
CREATE NONCLUSTERED INDEX [IDX_USERACCOUNT_EMAIL] ON [dbo].[UserAccount] ([Email] ASC)
GO

--DELETE INDEX
if exists(select * from sys.indexes where name = 'IDX_USERACCOUNT_FIRSTNAME' and type_desc = 'CLUSTERED')
DROP INDEX [IDX_USERACCOUNT_FIRSTNAME] ON [dbo].[UserAccount]
GO

--INDEX FOR TABLE [UserAccount] COLUMNS:[FirstName]
if not exists(select * from sys.indexes where name = 'IDX_USERACCOUNT_FIRSTNAME')
CREATE NONCLUSTERED INDEX [IDX_USERACCOUNT_FIRSTNAME] ON [dbo].[UserAccount] ([FirstName] ASC)
GO

--DELETE INDEX
if exists(select * from sys.indexes where name = 'IDX_USERACCOUNT_LASTNAME' and type_desc = 'CLUSTERED')
DROP INDEX [IDX_USERACCOUNT_LASTNAME] ON [dbo].[UserAccount]
GO

--INDEX FOR TABLE [UserAccount] COLUMNS:[LastName]
if not exists(select * from sys.indexes where name = 'IDX_USERACCOUNT_LASTNAME')
CREATE NONCLUSTERED INDEX [IDX_USERACCOUNT_LASTNAME] ON [dbo].[UserAccount] ([LastName] ASC)
GO

--DELETE INDEX
if exists(select * from sys.indexes where name = 'IDX_USERACCOUNT_USERTYPEID' and type_desc = 'CLUSTERED')
DROP INDEX [IDX_USERACCOUNT_USERTYPEID] ON [dbo].[UserAccount]
GO

--INDEX FOR TABLE [UserAccount] COLUMNS:[UserTypeId]
if not exists(select * from sys.indexes where name = 'IDX_USERACCOUNT_USERTYPEID')
CREATE NONCLUSTERED INDEX [IDX_USERACCOUNT_USERTYPEID] ON [dbo].[UserAccount] ([UserTypeId] ASC)
GO

--DELETE INDEX
if exists(select * from sys.indexes where name = 'IDX_USERTYPE_NAME' and type_desc = 'CLUSTERED')
DROP INDEX [IDX_USERTYPE_NAME] ON [dbo].[UserType]
GO

--INDEX FOR TABLE [UserType] COLUMNS:[Name]
if not exists(select * from sys.indexes where name = 'IDX_USERTYPE_NAME')
CREATE NONCLUSTERED INDEX [IDX_USERTYPE_NAME] ON [dbo].[UserType] ([Name] ASC)
GO

--DELETE INDEX
if exists(select * from sys.indexes where name = 'IDX_ZIP_NAME' and type_desc = 'CLUSTERED')
DROP INDEX [IDX_ZIP_NAME] ON [dbo].[Zip]
GO

--INDEX FOR TABLE [Zip] COLUMNS:[Name]
if not exists(select * from sys.indexes where name = 'IDX_ZIP_NAME')
CREATE NONCLUSTERED INDEX [IDX_ZIP_NAME] ON [dbo].[Zip] ([Name] ASC)
GO

--##SECTION END [CREATE INDEXES]

--##SECTION BEGIN [TENANT INDEXES]

--##SECTION END [TENANT INDEXES]

--##SECTION BEGIN [REMOVE DEFAULTS]

--BEGIN DEFAULTS FOR TABLE [Administrator]
DECLARE @defaultName varchar(max)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'Administrator' and c.name = 'Active')
if @defaultName IS NOT NULL
exec('ALTER TABLE [Administrator] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'Administrator' and c.name = 'AdministratorId')
if @defaultName IS NOT NULL
exec('ALTER TABLE [Administrator] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'Administrator' and c.name = 'Email')
if @defaultName IS NOT NULL
exec('ALTER TABLE [Administrator] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'Administrator' and c.name = 'FirstName')
if @defaultName IS NOT NULL
exec('ALTER TABLE [Administrator] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'Administrator' and c.name = 'LastIpAddress')
if @defaultName IS NOT NULL
exec('ALTER TABLE [Administrator] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'Administrator' and c.name = 'LastName')
if @defaultName IS NOT NULL
exec('ALTER TABLE [Administrator] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'Administrator' and c.name = 'Password')
if @defaultName IS NOT NULL
exec('ALTER TABLE [Administrator] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'Administrator' and c.name = 'UserName')
if @defaultName IS NOT NULL
exec('ALTER TABLE [Administrator] DROP CONSTRAINT ' + @defaultName)
--END DEFAULTS FOR TABLE [Administrator]
GO

--BEGIN DEFAULTS FOR TABLE [BodyType]
DECLARE @defaultName varchar(max)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'BodyType' and c.name = 'BodyTypeId')
if @defaultName IS NOT NULL
exec('ALTER TABLE [BodyType] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'BodyType' and c.name = 'Name')
if @defaultName IS NOT NULL
exec('ALTER TABLE [BodyType] DROP CONSTRAINT ' + @defaultName)
--END DEFAULTS FOR TABLE [BodyType]
GO

--BEGIN DEFAULTS FOR TABLE [BulletPoint]
DECLARE @defaultName varchar(max)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'BulletPoint' and c.name = 'BulletPointId')
if @defaultName IS NOT NULL
exec('ALTER TABLE [BulletPoint] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'BulletPoint' and c.name = 'ListingId')
if @defaultName IS NOT NULL
exec('ALTER TABLE [BulletPoint] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'BulletPoint' and c.name = 'Text')
if @defaultName IS NOT NULL
exec('ALTER TABLE [BulletPoint] DROP CONSTRAINT ' + @defaultName)
--END DEFAULTS FOR TABLE [BulletPoint]
GO

--BEGIN DEFAULTS FOR TABLE [City]
DECLARE @defaultName varchar(max)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'City' and c.name = 'CityId')
if @defaultName IS NOT NULL
exec('ALTER TABLE [City] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'City' and c.name = 'Name')
if @defaultName IS NOT NULL
exec('ALTER TABLE [City] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'City' and c.name = 'StateId')
if @defaultName IS NOT NULL
exec('ALTER TABLE [City] DROP CONSTRAINT ' + @defaultName)
--END DEFAULTS FOR TABLE [City]
GO

--BEGIN DEFAULTS FOR TABLE [CityZip]
DECLARE @defaultName varchar(max)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'CityZip' and c.name = 'CityId')
if @defaultName IS NOT NULL
exec('ALTER TABLE [CityZip] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'CityZip' and c.name = 'ZipId')
if @defaultName IS NOT NULL
exec('ALTER TABLE [CityZip] DROP CONSTRAINT ' + @defaultName)
--END DEFAULTS FOR TABLE [CityZip]
GO

--BEGIN DEFAULTS FOR TABLE [Color]
DECLARE @defaultName varchar(max)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'Color' and c.name = 'ColorId')
if @defaultName IS NOT NULL
exec('ALTER TABLE [Color] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'Color' and c.name = 'Name')
if @defaultName IS NOT NULL
exec('ALTER TABLE [Color] DROP CONSTRAINT ' + @defaultName)
--END DEFAULTS FOR TABLE [Color]
GO

--BEGIN DEFAULTS FOR TABLE [Condition]
DECLARE @defaultName varchar(max)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'Condition' and c.name = 'ConditionId')
if @defaultName IS NOT NULL
exec('ALTER TABLE [Condition] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'Condition' and c.name = 'Name')
if @defaultName IS NOT NULL
exec('ALTER TABLE [Condition] DROP CONSTRAINT ' + @defaultName)
--END DEFAULTS FOR TABLE [Condition]
GO

--BEGIN DEFAULTS FOR TABLE [ConfigSetting]
DECLARE @defaultName varchar(max)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'ConfigSetting' and c.name = 'ID')
if @defaultName IS NOT NULL
exec('ALTER TABLE [ConfigSetting] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'ConfigSetting' and c.name = 'Name')
if @defaultName IS NOT NULL
exec('ALTER TABLE [ConfigSetting] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'ConfigSetting' and c.name = 'Value')
if @defaultName IS NOT NULL
exec('ALTER TABLE [ConfigSetting] DROP CONSTRAINT ' + @defaultName)
--END DEFAULTS FOR TABLE [ConfigSetting]
GO

--BEGIN DEFAULTS FOR TABLE [Dealer]
DECLARE @defaultName varchar(max)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'Dealer' and c.name = 'CompanyName')
if @defaultName IS NOT NULL
exec('ALTER TABLE [Dealer] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'Dealer' and c.name = 'Directions')
if @defaultName IS NOT NULL
exec('ALTER TABLE [Dealer] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'Dealer' and c.name = 'MetroId')
if @defaultName IS NOT NULL
exec('ALTER TABLE [Dealer] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'Dealer' and c.name = 'UserId')
if @defaultName IS NOT NULL
exec('ALTER TABLE [Dealer] DROP CONSTRAINT ' + @defaultName)
--END DEFAULTS FOR TABLE [Dealer]
GO

--BEGIN DEFAULTS FOR TABLE [Feature]
DECLARE @defaultName varchar(max)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'Feature' and c.name = 'FeatureId')
if @defaultName IS NOT NULL
exec('ALTER TABLE [Feature] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'Feature' and c.name = 'Name')
if @defaultName IS NOT NULL
exec('ALTER TABLE [Feature] DROP CONSTRAINT ' + @defaultName)
--END DEFAULTS FOR TABLE [Feature]
GO

--BEGIN DEFAULTS FOR TABLE [FuelType]
DECLARE @defaultName varchar(max)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'FuelType' and c.name = 'FuelTypeId')
if @defaultName IS NOT NULL
exec('ALTER TABLE [FuelType] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'FuelType' and c.name = 'Name')
if @defaultName IS NOT NULL
exec('ALTER TABLE [FuelType] DROP CONSTRAINT ' + @defaultName)
--END DEFAULTS FOR TABLE [FuelType]
GO

--BEGIN DEFAULTS FOR TABLE [Listing]
DECLARE @defaultName varchar(max)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'Listing' and c.name = 'Active')
if @defaultName IS NOT NULL
exec('ALTER TABLE [Listing] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'Listing' and c.name = 'BodyTypeId')
if @defaultName IS NOT NULL
exec('ALTER TABLE [Listing] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'Listing' and c.name = 'ColorExtId')
if @defaultName IS NOT NULL
exec('ALTER TABLE [Listing] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'Listing' and c.name = 'ColorIntId')
if @defaultName IS NOT NULL
exec('ALTER TABLE [Listing] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'Listing' and c.name = 'ConditionId')
if @defaultName IS NOT NULL
exec('ALTER TABLE [Listing] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'Listing' and c.name = 'Cylinders')
if @defaultName IS NOT NULL
exec('ALTER TABLE [Listing] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'Listing' and c.name = 'Description')
if @defaultName IS NOT NULL
exec('ALTER TABLE [Listing] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'Listing' and c.name = 'Disclaimer')
if @defaultName IS NOT NULL
exec('ALTER TABLE [Listing] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'Listing' and c.name = 'Doors')
if @defaultName IS NOT NULL
exec('ALTER TABLE [Listing] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'Listing' and c.name = 'Engine')
if @defaultName IS NOT NULL
exec('ALTER TABLE [Listing] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'Listing' and c.name = 'ExpirationDate')
if @defaultName IS NOT NULL
exec('ALTER TABLE [Listing] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'Listing' and c.name = 'FuelTypeId')
if @defaultName IS NOT NULL
exec('ALTER TABLE [Listing] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'Listing' and c.name = 'Invoice')
if @defaultName IS NOT NULL
exec('ALTER TABLE [Listing] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'Listing' and c.name = 'IsFeatured')
if @defaultName IS NOT NULL
exec('ALTER TABLE [Listing] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'Listing' and c.name = 'ListDate')
if @defaultName IS NOT NULL
exec('ALTER TABLE [Listing] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'Listing' and c.name = 'ListingId')
if @defaultName IS NOT NULL
exec('ALTER TABLE [Listing] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'Listing' and c.name = 'MakeModelId')
if @defaultName IS NOT NULL
exec('ALTER TABLE [Listing] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'Listing' and c.name = 'MetroId')
if @defaultName IS NOT NULL
exec('ALTER TABLE [Listing] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'Listing' and c.name = 'Mileage')
if @defaultName IS NOT NULL
exec('ALTER TABLE [Listing] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'Listing' and c.name = 'Price')
if @defaultName IS NOT NULL
exec('ALTER TABLE [Listing] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'Listing' and c.name = 'StockNumber')
if @defaultName IS NOT NULL
exec('ALTER TABLE [Listing] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'Listing' and c.name = 'Title')
if @defaultName IS NOT NULL
exec('ALTER TABLE [Listing] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'Listing' and c.name = 'TransmissionId')
if @defaultName IS NOT NULL
exec('ALTER TABLE [Listing] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'Listing' and c.name = 'TrimLevel')
if @defaultName IS NOT NULL
exec('ALTER TABLE [Listing] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'Listing' and c.name = 'UserId')
if @defaultName IS NOT NULL
exec('ALTER TABLE [Listing] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'Listing' and c.name = 'Vin')
if @defaultName IS NOT NULL
exec('ALTER TABLE [Listing] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'Listing' and c.name = 'Year')
if @defaultName IS NOT NULL
exec('ALTER TABLE [Listing] DROP CONSTRAINT ' + @defaultName)
--END DEFAULTS FOR TABLE [Listing]
GO

--BEGIN DEFAULTS FOR TABLE [ListingFeature]
DECLARE @defaultName varchar(max)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'ListingFeature' and c.name = 'FeatureId')
if @defaultName IS NOT NULL
exec('ALTER TABLE [ListingFeature] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'ListingFeature' and c.name = 'ListingId')
if @defaultName IS NOT NULL
exec('ALTER TABLE [ListingFeature] DROP CONSTRAINT ' + @defaultName)
--END DEFAULTS FOR TABLE [ListingFeature]
GO

--BEGIN DEFAULTS FOR TABLE [ListingImage]
DECLARE @defaultName varchar(max)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'ListingImage' and c.name = 'FileName')
if @defaultName IS NOT NULL
exec('ALTER TABLE [ListingImage] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'ListingImage' and c.name = 'ListingId')
if @defaultName IS NOT NULL
exec('ALTER TABLE [ListingImage] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'ListingImage' and c.name = 'ListingImageId')
if @defaultName IS NOT NULL
exec('ALTER TABLE [ListingImage] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'ListingImage' and c.name = 'SortOrder')
if @defaultName IS NOT NULL
exec('ALTER TABLE [ListingImage] DROP CONSTRAINT ' + @defaultName)
--END DEFAULTS FOR TABLE [ListingImage]
GO

--BEGIN DEFAULTS FOR TABLE [ListingPremium]
DECLARE @defaultName varchar(max)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'ListingPremium' and c.name = 'Active')
if @defaultName IS NOT NULL
exec('ALTER TABLE [ListingPremium] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'ListingPremium' and c.name = 'CityName')
if @defaultName IS NOT NULL
exec('ALTER TABLE [ListingPremium] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'ListingPremium' and c.name = 'ExpirationDate')
if @defaultName IS NOT NULL
exec('ALTER TABLE [ListingPremium] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'ListingPremium' and c.name = 'ListingId')
if @defaultName IS NOT NULL
exec('ALTER TABLE [ListingPremium] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'ListingPremium' and c.name = 'ListingPremiumId')
if @defaultName IS NOT NULL
exec('ALTER TABLE [ListingPremium] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'ListingPremium' and c.name = 'StartDate')
if @defaultName IS NOT NULL
exec('ALTER TABLE [ListingPremium] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'ListingPremium' and c.name = 'StateId')
if @defaultName IS NOT NULL
exec('ALTER TABLE [ListingPremium] DROP CONSTRAINT ' + @defaultName)
--END DEFAULTS FOR TABLE [ListingPremium]
GO

--BEGIN DEFAULTS FOR TABLE [ListingSaved]
DECLARE @defaultName varchar(max)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'ListingSaved' and c.name = 'ListingId')
if @defaultName IS NOT NULL
exec('ALTER TABLE [ListingSaved] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'ListingSaved' and c.name = 'UserId')
if @defaultName IS NOT NULL
exec('ALTER TABLE [ListingSaved] DROP CONSTRAINT ' + @defaultName)
--END DEFAULTS FOR TABLE [ListingSaved]
GO

--BEGIN DEFAULTS FOR TABLE [ListingView]
DECLARE @defaultName varchar(max)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'ListingView' and c.name = 'ListingId')
if @defaultName IS NOT NULL
exec('ALTER TABLE [ListingView] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'ListingView' and c.name = 'ListingViewId')
if @defaultName IS NOT NULL
exec('ALTER TABLE [ListingView] DROP CONSTRAINT ' + @defaultName)
--END DEFAULTS FOR TABLE [ListingView]
GO

--BEGIN DEFAULTS FOR TABLE [Make]
DECLARE @defaultName varchar(max)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'Make' and c.name = 'MakeId')
if @defaultName IS NOT NULL
exec('ALTER TABLE [Make] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'Make' and c.name = 'Name')
if @defaultName IS NOT NULL
exec('ALTER TABLE [Make] DROP CONSTRAINT ' + @defaultName)
--END DEFAULTS FOR TABLE [Make]
GO

--BEGIN DEFAULTS FOR TABLE [MakeModel]
DECLARE @defaultName varchar(max)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'MakeModel' and c.name = 'MakeId')
if @defaultName IS NOT NULL
exec('ALTER TABLE [MakeModel] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'MakeModel' and c.name = 'MakeModelId')
if @defaultName IS NOT NULL
exec('ALTER TABLE [MakeModel] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'MakeModel' and c.name = 'ModelId')
if @defaultName IS NOT NULL
exec('ALTER TABLE [MakeModel] DROP CONSTRAINT ' + @defaultName)
--END DEFAULTS FOR TABLE [MakeModel]
GO

--BEGIN DEFAULTS FOR TABLE [Metro]
DECLARE @defaultName varchar(max)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'Metro' and c.name = 'IsPopular')
if @defaultName IS NOT NULL
exec('ALTER TABLE [Metro] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'Metro' and c.name = 'MetroId')
if @defaultName IS NOT NULL
exec('ALTER TABLE [Metro] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'Metro' and c.name = 'Name')
if @defaultName IS NOT NULL
exec('ALTER TABLE [Metro] DROP CONSTRAINT ' + @defaultName)
--END DEFAULTS FOR TABLE [Metro]
GO

--BEGIN DEFAULTS FOR TABLE [MetroState]
DECLARE @defaultName varchar(max)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'MetroState' and c.name = 'MetroId')
if @defaultName IS NOT NULL
exec('ALTER TABLE [MetroState] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'MetroState' and c.name = 'StateId')
if @defaultName IS NOT NULL
exec('ALTER TABLE [MetroState] DROP CONSTRAINT ' + @defaultName)
--END DEFAULTS FOR TABLE [MetroState]
GO

--BEGIN DEFAULTS FOR TABLE [MetroZip]
DECLARE @defaultName varchar(max)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'MetroZip' and c.name = 'MetroId')
if @defaultName IS NOT NULL
exec('ALTER TABLE [MetroZip] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'MetroZip' and c.name = 'ZipId')
if @defaultName IS NOT NULL
exec('ALTER TABLE [MetroZip] DROP CONSTRAINT ' + @defaultName)
--END DEFAULTS FOR TABLE [MetroZip]
GO

--BEGIN DEFAULTS FOR TABLE [Model]
DECLARE @defaultName varchar(max)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'Model' and c.name = 'ModelId')
if @defaultName IS NOT NULL
exec('ALTER TABLE [Model] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'Model' and c.name = 'MpgCity')
if @defaultName IS NOT NULL
exec('ALTER TABLE [Model] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'Model' and c.name = 'MpgHighway')
if @defaultName IS NOT NULL
exec('ALTER TABLE [Model] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'Model' and c.name = 'Name')
if @defaultName IS NOT NULL
exec('ALTER TABLE [Model] DROP CONSTRAINT ' + @defaultName)
--END DEFAULTS FOR TABLE [Model]
GO

--BEGIN DEFAULTS FOR TABLE [SearchSaved]
DECLARE @defaultName varchar(max)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'SearchSaved' and c.name = 'Location')
if @defaultName IS NOT NULL
exec('ALTER TABLE [SearchSaved] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'SearchSaved' and c.name = 'Name')
if @defaultName IS NOT NULL
exec('ALTER TABLE [SearchSaved] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'SearchSaved' and c.name = 'Radius')
if @defaultName IS NOT NULL
exec('ALTER TABLE [SearchSaved] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'SearchSaved' and c.name = 'SearchSavedId')
if @defaultName IS NOT NULL
exec('ALTER TABLE [SearchSaved] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'SearchSaved' and c.name = 'Text')
if @defaultName IS NOT NULL
exec('ALTER TABLE [SearchSaved] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'SearchSaved' and c.name = 'UserId')
if @defaultName IS NOT NULL
exec('ALTER TABLE [SearchSaved] DROP CONSTRAINT ' + @defaultName)
--END DEFAULTS FOR TABLE [SearchSaved]
GO

--BEGIN DEFAULTS FOR TABLE [SearchSavedCriteria]
DECLARE @defaultName varchar(max)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'SearchSavedCriteria' and c.name = 'Didx')
if @defaultName IS NOT NULL
exec('ALTER TABLE [SearchSavedCriteria] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'SearchSavedCriteria' and c.name = 'Dvidx')
if @defaultName IS NOT NULL
exec('ALTER TABLE [SearchSavedCriteria] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'SearchSavedCriteria' and c.name = 'SearchSavedCriteriaId')
if @defaultName IS NOT NULL
exec('ALTER TABLE [SearchSavedCriteria] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'SearchSavedCriteria' and c.name = 'SearchSavedId')
if @defaultName IS NOT NULL
exec('ALTER TABLE [SearchSavedCriteria] DROP CONSTRAINT ' + @defaultName)
--END DEFAULTS FOR TABLE [SearchSavedCriteria]
GO

--BEGIN DEFAULTS FOR TABLE [State]
DECLARE @defaultName varchar(max)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'State' and c.name = 'Abbr')
if @defaultName IS NOT NULL
exec('ALTER TABLE [State] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'State' and c.name = 'Description')
if @defaultName IS NOT NULL
exec('ALTER TABLE [State] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'State' and c.name = 'Name')
if @defaultName IS NOT NULL
exec('ALTER TABLE [State] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'State' and c.name = 'StateId')
if @defaultName IS NOT NULL
exec('ALTER TABLE [State] DROP CONSTRAINT ' + @defaultName)
--END DEFAULTS FOR TABLE [State]
GO

--BEGIN DEFAULTS FOR TABLE [Transmission]
DECLARE @defaultName varchar(max)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'Transmission' and c.name = 'Name')
if @defaultName IS NOT NULL
exec('ALTER TABLE [Transmission] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'Transmission' and c.name = 'TransmissionId')
if @defaultName IS NOT NULL
exec('ALTER TABLE [Transmission] DROP CONSTRAINT ' + @defaultName)
--END DEFAULTS FOR TABLE [Transmission]
GO

--BEGIN DEFAULTS FOR TABLE [UserAccount]
DECLARE @defaultName varchar(max)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'UserAccount' and c.name = 'AcceptedAdvertTerms')
if @defaultName IS NOT NULL
exec('ALTER TABLE [UserAccount] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'UserAccount' and c.name = 'Active')
if @defaultName IS NOT NULL
exec('ALTER TABLE [UserAccount] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'UserAccount' and c.name = 'Address1')
if @defaultName IS NOT NULL
exec('ALTER TABLE [UserAccount] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'UserAccount' and c.name = 'Address2')
if @defaultName IS NOT NULL
exec('ALTER TABLE [UserAccount] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'UserAccount' and c.name = 'AlertFrequency')
if @defaultName IS NOT NULL
exec('ALTER TABLE [UserAccount] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'UserAccount' and c.name = 'AlertSent')
if @defaultName IS NOT NULL
exec('ALTER TABLE [UserAccount] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'UserAccount' and c.name = 'City')
if @defaultName IS NOT NULL
exec('ALTER TABLE [UserAccount] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'UserAccount' and c.name = 'Description')
if @defaultName IS NOT NULL
exec('ALTER TABLE [UserAccount] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'UserAccount' and c.name = 'Email')
if @defaultName IS NOT NULL
exec('ALTER TABLE [UserAccount] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'UserAccount' and c.name = 'FirstName')
if @defaultName IS NOT NULL
exec('ALTER TABLE [UserAccount] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'UserAccount' and c.name = 'HomePhone')
if @defaultName IS NOT NULL
exec('ALTER TABLE [UserAccount] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'UserAccount' and c.name = 'LastName')
if @defaultName IS NOT NULL
exec('ALTER TABLE [UserAccount] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'UserAccount' and c.name = 'Latitude')
if @defaultName IS NOT NULL
exec('ALTER TABLE [UserAccount] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'UserAccount' and c.name = 'Longitude')
if @defaultName IS NOT NULL
exec('ALTER TABLE [UserAccount] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'UserAccount' and c.name = 'MobilePhone')
if @defaultName IS NOT NULL
exec('ALTER TABLE [UserAccount] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'UserAccount' and c.name = 'OfficeFax')
if @defaultName IS NOT NULL
exec('ALTER TABLE [UserAccount] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'UserAccount' and c.name = 'OfficePhone')
if @defaultName IS NOT NULL
exec('ALTER TABLE [UserAccount] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'UserAccount' and c.name = 'OfficePhoneExt')
if @defaultName IS NOT NULL
exec('ALTER TABLE [UserAccount] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'UserAccount' and c.name = 'Password')
if @defaultName IS NOT NULL
exec('ALTER TABLE [UserAccount] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'UserAccount' and c.name = 'StateId')
if @defaultName IS NOT NULL
exec('ALTER TABLE [UserAccount] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'UserAccount' and c.name = 'UserId')
if @defaultName IS NOT NULL
exec('ALTER TABLE [UserAccount] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'UserAccount' and c.name = 'UserTypeId')
if @defaultName IS NOT NULL
exec('ALTER TABLE [UserAccount] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'UserAccount' and c.name = 'ZipId')
if @defaultName IS NOT NULL
exec('ALTER TABLE [UserAccount] DROP CONSTRAINT ' + @defaultName)
--END DEFAULTS FOR TABLE [UserAccount]
GO

--BEGIN DEFAULTS FOR TABLE [UserLoginHistory]
DECLARE @defaultName varchar(max)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'UserLoginHistory' and c.name = 'BrowserAgent')
if @defaultName IS NOT NULL
exec('ALTER TABLE [UserLoginHistory] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'UserLoginHistory' and c.name = 'IpAddress')
if @defaultName IS NOT NULL
exec('ALTER TABLE [UserLoginHistory] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'UserLoginHistory' and c.name = 'UserId')
if @defaultName IS NOT NULL
exec('ALTER TABLE [UserLoginHistory] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'UserLoginHistory' and c.name = 'UserLoginHistoryId')
if @defaultName IS NOT NULL
exec('ALTER TABLE [UserLoginHistory] DROP CONSTRAINT ' + @defaultName)
--END DEFAULTS FOR TABLE [UserLoginHistory]
GO

--BEGIN DEFAULTS FOR TABLE [UserType]
DECLARE @defaultName varchar(max)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'UserType' and c.name = 'Active')
if @defaultName IS NOT NULL
exec('ALTER TABLE [UserType] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'UserType' and c.name = 'Name')
if @defaultName IS NOT NULL
exec('ALTER TABLE [UserType] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'UserType' and c.name = 'UserTypeId')
if @defaultName IS NOT NULL
exec('ALTER TABLE [UserType] DROP CONSTRAINT ' + @defaultName)
--END DEFAULTS FOR TABLE [UserType]
GO

--BEGIN DEFAULTS FOR TABLE [VistorContact]
DECLARE @defaultName varchar(max)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'VistorContact' and c.name = 'Email')
if @defaultName IS NOT NULL
exec('ALTER TABLE [VistorContact] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'VistorContact' and c.name = 'IpAddress')
if @defaultName IS NOT NULL
exec('ALTER TABLE [VistorContact] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'VistorContact' and c.name = 'IsHandled')
if @defaultName IS NOT NULL
exec('ALTER TABLE [VistorContact] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'VistorContact' and c.name = 'Message')
if @defaultName IS NOT NULL
exec('ALTER TABLE [VistorContact] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'VistorContact' and c.name = 'Name')
if @defaultName IS NOT NULL
exec('ALTER TABLE [VistorContact] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'VistorContact' and c.name = 'Phone')
if @defaultName IS NOT NULL
exec('ALTER TABLE [VistorContact] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'VistorContact' and c.name = 'UserId')
if @defaultName IS NOT NULL
exec('ALTER TABLE [VistorContact] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'VistorContact' and c.name = 'VisitorContactId')
if @defaultName IS NOT NULL
exec('ALTER TABLE [VistorContact] DROP CONSTRAINT ' + @defaultName)
--END DEFAULTS FOR TABLE [VistorContact]
GO

--BEGIN DEFAULTS FOR TABLE [Zip]
DECLARE @defaultName varchar(max)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'Zip' and c.name = 'Latitude')
if @defaultName IS NOT NULL
exec('ALTER TABLE [Zip] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'Zip' and c.name = 'Longitude')
if @defaultName IS NOT NULL
exec('ALTER TABLE [Zip] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'Zip' and c.name = 'Name')
if @defaultName IS NOT NULL
exec('ALTER TABLE [Zip] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'Zip' and c.name = 'StateId')
if @defaultName IS NOT NULL
exec('ALTER TABLE [Zip] DROP CONSTRAINT ' + @defaultName)
SET @defaultName = (SELECT d.name FROM sys.columns c inner join sys.default_constraints d on c.column_id = d.parent_column_id and c.object_id = d.parent_object_id inner join sys.objects o on d.parent_object_id = o.object_id where o.name = 'Zip' and c.name = 'ZipId')
if @defaultName IS NOT NULL
exec('ALTER TABLE [Zip] DROP CONSTRAINT ' + @defaultName)
--END DEFAULTS FOR TABLE [Zip]
GO

--##SECTION END [REMOVE DEFAULTS]

--##SECTION BEGIN [CREATE DEFAULTS]

--BEGIN DEFAULTS FOR TABLE [Administrator]
if not exists(select * from sys.objects where name = 'DF__ADMINISTRATOR_ACTIVE' and type = 'D' and type_desc = 'DEFAULT_CONSTRAINT')
ALTER TABLE [dbo].[Administrator] ADD CONSTRAINT [DF__ADMINISTRATOR_ACTIVE] DEFAULT (1) FOR [Active]

if not exists(select * from sys.objects where name = 'DF__ADMINISTRATOR_LASTIPADDRESS' and type = 'D' and type_desc = 'DEFAULT_CONSTRAINT')
ALTER TABLE [dbo].[Administrator] ADD CONSTRAINT [DF__ADMINISTRATOR_LASTIPADDRESS] DEFAULT ('0.0.0.0') FOR [LastIpAddress]

--END DEFAULTS FOR TABLE [Administrator]
GO

--BEGIN DEFAULTS FOR TABLE [Listing]
if not exists(select * from sys.objects where name = 'DF__LISTING_ACTIVE' and type = 'D' and type_desc = 'DEFAULT_CONSTRAINT')
ALTER TABLE [dbo].[Listing] ADD CONSTRAINT [DF__LISTING_ACTIVE] DEFAULT (1) FOR [Active]

if not exists(select * from sys.objects where name = 'DF__LISTING_EXPIRATIONDATE' and type = 'D' and type_desc = 'DEFAULT_CONSTRAINT')
ALTER TABLE [dbo].[Listing] ADD CONSTRAINT [DF__LISTING_EXPIRATIONDATE] DEFAULT (getdate()) FOR [ExpirationDate]

--END DEFAULTS FOR TABLE [Listing]
GO

--BEGIN DEFAULTS FOR TABLE [ListingPremium]
if not exists(select * from sys.objects where name = 'DF__LISTINGPREMIUM_ACTIVE' and type = 'D' and type_desc = 'DEFAULT_CONSTRAINT')
ALTER TABLE [dbo].[ListingPremium] ADD CONSTRAINT [DF__LISTINGPREMIUM_ACTIVE] DEFAULT (1) FOR [Active]

--END DEFAULTS FOR TABLE [ListingPremium]
GO

--BEGIN DEFAULTS FOR TABLE [Metro]
if not exists(select * from sys.objects where name = 'DF__METRO_ISPOPULAR' and type = 'D' and type_desc = 'DEFAULT_CONSTRAINT')
ALTER TABLE [dbo].[Metro] ADD CONSTRAINT [DF__METRO_ISPOPULAR] DEFAULT ('0') FOR [IsPopular]

--END DEFAULTS FOR TABLE [Metro]
GO

--BEGIN DEFAULTS FOR TABLE [UserAccount]
if not exists(select * from sys.objects where name = 'DF__USERACCOUNT_ACCEPTEDADVERTTERMS' and type = 'D' and type_desc = 'DEFAULT_CONSTRAINT')
ALTER TABLE [dbo].[UserAccount] ADD CONSTRAINT [DF__USERACCOUNT_ACCEPTEDADVERTTERMS] DEFAULT (0) FOR [AcceptedAdvertTerms]

if not exists(select * from sys.objects where name = 'DF__USERACCOUNT_ACTIVE' and type = 'D' and type_desc = 'DEFAULT_CONSTRAINT')
ALTER TABLE [dbo].[UserAccount] ADD CONSTRAINT [DF__USERACCOUNT_ACTIVE] DEFAULT (1) FOR [Active]

if not exists(select * from sys.objects where name = 'DF__USERACCOUNT_ALERTFREQUENCY' and type = 'D' and type_desc = 'DEFAULT_CONSTRAINT')
ALTER TABLE [dbo].[UserAccount] ADD CONSTRAINT [DF__USERACCOUNT_ALERTFREQUENCY] DEFAULT (7) FOR [AlertFrequency]

if not exists(select * from sys.objects where name = 'DF__USERACCOUNT_ALERTSENT' and type = 'D' and type_desc = 'DEFAULT_CONSTRAINT')
ALTER TABLE [dbo].[UserAccount] ADD CONSTRAINT [DF__USERACCOUNT_ALERTSENT] DEFAULT (getdate()) FOR [AlertSent]

--END DEFAULTS FOR TABLE [UserAccount]
GO

--BEGIN DEFAULTS FOR TABLE [UserLoginHistory]
if not exists(select * from sys.objects where name = 'DF__USERLOGINHISTORY_IPADDRESS' and type = 'D' and type_desc = 'DEFAULT_CONSTRAINT')
ALTER TABLE [dbo].[UserLoginHistory] ADD CONSTRAINT [DF__USERLOGINHISTORY_IPADDRESS] DEFAULT ('000.000.000.000') FOR [IpAddress]

--END DEFAULTS FOR TABLE [UserLoginHistory]
GO

--BEGIN DEFAULTS FOR TABLE [UserType]
if not exists(select * from sys.objects where name = 'DF__USERTYPE_ACTIVE' and type = 'D' and type_desc = 'DEFAULT_CONSTRAINT')
ALTER TABLE [dbo].[UserType] ADD CONSTRAINT [DF__USERTYPE_ACTIVE] DEFAULT (1) FOR [Active]

--END DEFAULTS FOR TABLE [UserType]
GO

--BEGIN DEFAULTS FOR TABLE [VistorContact]
if not exists(select * from sys.objects where name = 'DF__VISTORCONTACT_IPADDRESS' and type = 'D' and type_desc = 'DEFAULT_CONSTRAINT')
ALTER TABLE [dbo].[VistorContact] ADD CONSTRAINT [DF__VISTORCONTACT_IPADDRESS] DEFAULT ('000.000.000.000') FOR [IpAddress]

if not exists(select * from sys.objects where name = 'DF__VISTORCONTACT_ISHANDLED' and type = 'D' and type_desc = 'DEFAULT_CONSTRAINT')
ALTER TABLE [dbo].[VistorContact] ADD CONSTRAINT [DF__VISTORCONTACT_ISHANDLED] DEFAULT (0) FOR [IsHandled]

--END DEFAULTS FOR TABLE [VistorContact]
GO

--##SECTION END [CREATE DEFAULTS]

if not exists(select * from sys.objects where [name] = '__nhydrateschema' and [type] = 'U')
BEGIN
CREATE TABLE [__nhydrateschema] (
[dbVersion] [varchar] (50) NOT NULL,
[LastUpdate] [datetime] NOT NULL,
[ModelKey] [uniqueidentifier] NOT NULL,
[History] [nvarchar](max) NOT NULL
)
if not exists(select * from sys.objects where [name] = '__pk__nhydrateschema' and [type] = 'PK')
ALTER TABLE [__nhydrateschema] WITH NOCHECK ADD CONSTRAINT [__pk__nhydrateschema] PRIMARY KEY CLUSTERED ([ModelKey])
END
GO

if not exists(select * from sys.objects where name = '__nhydrateobjects' and [type] = 'U')
CREATE TABLE [dbo].[__nhydrateobjects]
(
	[rowid] [bigint] IDENTITY(1,1) NOT NULL,
	[id] [uniqueidentifier] NULL,
	[name] [varchar](500) NOT NULL,
	[type] [varchar](10) NOT NULL,
	[schema] [varchar](500) NULL,
	[CreatedDate] [datetime] NOT NULL,
	[ModifiedDate] [datetime] NOT NULL,
	[Hash] [varchar](32) NULL,
	[ModelKey] [uniqueidentifier] NOT NULL,
)

if not exists(select * from sys.indexes where name = '__ix__nhydrateobjects_name')
CREATE NONCLUSTERED INDEX [__ix__nhydrateobjects_name] ON [dbo].[__nhydrateobjects]
(
	[name] ASC
)

if not exists(select * from sys.indexes where name = '__ix__nhydrateobjects_schema')
CREATE NONCLUSTERED INDEX [__ix__nhydrateobjects_schema] ON [dbo].[__nhydrateobjects] 
(
	[schema] ASC
)

if not exists(select * from sys.indexes where name = '__ix__nhydrateobjects_type')
CREATE NONCLUSTERED INDEX [__ix__nhydrateobjects_type] ON [dbo].[__nhydrateobjects] 
(
	[type] ASC
)

if not exists(select * from sys.indexes where name = '__ix__nhydrateobjects_modelkey')
CREATE NONCLUSTERED INDEX [__ix__nhydrateobjects_modelkey] ON [dbo].[__nhydrateobjects] 
(
	[ModelKey] ASC
)

if not exists(select * from sys.indexes where name = '__pk__nhydrateobjects')
ALTER TABLE [dbo].[__nhydrateobjects] ADD CONSTRAINT [__pk__nhydrateobjects] PRIMARY KEY CLUSTERED 
(
	[rowid] ASC
)
GO

